wallet2_api: implement runtime proxy configuration
This commit is contained in:
@@ -938,13 +938,13 @@ string WalletImpl::keysFilename() const
|
||||
return m_wallet->get_keys_file();
|
||||
}
|
||||
|
||||
bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password, bool use_ssl, bool lightWallet)
|
||||
bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password, bool use_ssl, bool lightWallet, const std::string &proxy_address)
|
||||
{
|
||||
clearStatus();
|
||||
m_wallet->set_light_wallet(lightWallet);
|
||||
if(daemon_username != "")
|
||||
m_daemon_login.emplace(daemon_username, daemon_password);
|
||||
return doInit(daemon_address, upper_transaction_size_limit, use_ssl);
|
||||
return doInit(daemon_address, proxy_address, upper_transaction_size_limit, use_ssl);
|
||||
}
|
||||
|
||||
bool WalletImpl::lightWalletLogin(bool &isNewWallet) const
|
||||
@@ -2088,6 +2088,11 @@ bool WalletImpl::trustedDaemon() const
|
||||
return m_wallet->is_trusted_daemon();
|
||||
}
|
||||
|
||||
bool WalletImpl::setProxy(const std::string &address)
|
||||
{
|
||||
return m_wallet->set_proxy(address);
|
||||
}
|
||||
|
||||
bool WalletImpl::watchOnly() const
|
||||
{
|
||||
return m_wallet->watch_only();
|
||||
@@ -2241,9 +2246,9 @@ void WalletImpl::pendingTxPostProcess(PendingTransactionImpl * pending)
|
||||
pending->m_pending_tx = exported_txs.ptx;
|
||||
}
|
||||
|
||||
bool WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction_size_limit, bool ssl)
|
||||
bool WalletImpl::doInit(const string &daemon_address, const std::string &proxy_address, uint64_t upper_transaction_size_limit, bool ssl)
|
||||
{
|
||||
if (!m_wallet->init(daemon_address, m_daemon_login, boost::asio::ip::tcp::endpoint{}, upper_transaction_size_limit))
|
||||
if (!m_wallet->init(daemon_address, m_daemon_login, proxy_address, upper_transaction_size_limit))
|
||||
return false;
|
||||
|
||||
// in case new wallet, this will force fast-refresh (pulling hashes instead of blocks)
|
||||
|
||||
@@ -102,11 +102,12 @@ public:
|
||||
bool store(const std::string &path) override;
|
||||
std::string filename() const override;
|
||||
std::string keysFilename() const override;
|
||||
bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false) override;
|
||||
bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false, const std::string &proxy_address = "") override;
|
||||
bool connectToDaemon() override;
|
||||
ConnectionStatus connected() const override;
|
||||
void setTrustedDaemon(bool arg) override;
|
||||
bool trustedDaemon() const override;
|
||||
bool setProxy(const std::string &address) override;
|
||||
uint64_t balance(uint32_t accountIndex = 0) const override;
|
||||
uint64_t unlockedBalance(uint32_t accountIndex = 0) const override;
|
||||
uint64_t blockChainHeight() const override;
|
||||
@@ -225,7 +226,7 @@ private:
|
||||
void stopRefresh();
|
||||
bool isNewWallet() const;
|
||||
void pendingTxPostProcess(PendingTransactionImpl * pending);
|
||||
bool doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, bool ssl = false);
|
||||
bool doInit(const std::string &daemon_address, const std::string &proxy_address, uint64_t upper_transaction_size_limit = 0, bool ssl = false);
|
||||
|
||||
private:
|
||||
friend class PendingTransactionImpl;
|
||||
|
||||
@@ -533,9 +533,10 @@ struct Wallet
|
||||
* \param daemon_username
|
||||
* \param daemon_password
|
||||
* \param lightWallet - start wallet in light mode, connect to a openmonero compatible server.
|
||||
* \param proxy_address - set proxy address, empty string to disable
|
||||
* \return - true on success
|
||||
*/
|
||||
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false) = 0;
|
||||
virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = "", bool use_ssl = false, bool lightWallet = false, const std::string &proxy_address = "") = 0;
|
||||
|
||||
/*!
|
||||
* \brief createWatchOnly - Creates a watch only wallet
|
||||
@@ -594,6 +595,7 @@ struct Wallet
|
||||
virtual ConnectionStatus connected() const = 0;
|
||||
virtual void setTrustedDaemon(bool arg) = 0;
|
||||
virtual bool trustedDaemon() const = 0;
|
||||
virtual bool setProxy(const std::string &address) = 0;
|
||||
virtual uint64_t balance(uint32_t accountIndex = 0) const = 0;
|
||||
uint64_t balanceAll() const {
|
||||
uint64_t result = 0;
|
||||
@@ -1298,6 +1300,9 @@ struct WalletManager
|
||||
std::string subdir,
|
||||
const char *buildtag = nullptr,
|
||||
const char *current_version = nullptr);
|
||||
|
||||
//! sets proxy address, empty string to disable
|
||||
virtual bool setProxy(const std::string &address) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -375,6 +375,10 @@ std::tuple<bool, std::string, std::string, std::string, std::string> WalletManag
|
||||
return std::make_tuple(false, "", "", "", "");
|
||||
}
|
||||
|
||||
bool WalletManagerImpl::setProxy(const std::string &address)
|
||||
{
|
||||
return m_http_client.set_proxy(address);
|
||||
}
|
||||
|
||||
///////////////////// WalletManagerFactory implementation //////////////////////
|
||||
WalletManager *WalletManagerFactory::getWalletManager()
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
|
||||
#include "wallet/api/wallet2_api.h"
|
||||
#include "net/http_client.h"
|
||||
#include "net/http.h"
|
||||
#include <string>
|
||||
|
||||
namespace Monero {
|
||||
@@ -92,11 +92,12 @@ public:
|
||||
bool startMining(const std::string &address, uint32_t threads = 1, bool background_mining = false, bool ignore_battery = true) override;
|
||||
bool stopMining() override;
|
||||
std::string resolveOpenAlias(const std::string &address, bool &dnssec_valid) const override;
|
||||
bool setProxy(const std::string &address) override;
|
||||
|
||||
private:
|
||||
WalletManagerImpl() {}
|
||||
friend struct WalletManagerFactory;
|
||||
epee::net_utils::http::http_simple_client m_http_client;
|
||||
net::http::client m_http_client;
|
||||
std::string m_errorString;
|
||||
};
|
||||
|
||||
|
||||
+12
-28
@@ -48,6 +48,7 @@ using namespace epee;
|
||||
#include "wallet_rpc_helpers.h"
|
||||
#include "wallet2.h"
|
||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||
#include "net/parse.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
#include "rpc/core_rpc_server_error_codes.h"
|
||||
#include "rpc/rpc_payment_signature.h"
|
||||
@@ -440,30 +441,14 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
|
||||
);
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::endpoint proxy{};
|
||||
std::string proxy;
|
||||
if (use_proxy)
|
||||
{
|
||||
namespace ip = boost::asio::ip;
|
||||
|
||||
const auto proxy_address = command_line::get_arg(vm, opts.proxy);
|
||||
|
||||
boost::string_ref proxy_port{proxy_address};
|
||||
boost::string_ref proxy_host = proxy_port.substr(0, proxy_port.rfind(":"));
|
||||
if (proxy_port.size() == proxy_host.size())
|
||||
proxy_host = "127.0.0.1";
|
||||
else
|
||||
proxy_port = proxy_port.substr(proxy_host.size() + 1);
|
||||
|
||||
uint16_t port_value = 0;
|
||||
proxy = command_line::get_arg(vm, opts.proxy);
|
||||
THROW_WALLET_EXCEPTION_IF(
|
||||
!epee::string_tools::get_xtype_from_string(port_value, std::string{proxy_port}),
|
||||
!net::get_tcp_endpoint(proxy),
|
||||
tools::error::wallet_internal_error,
|
||||
std::string{"Invalid port specified for --"} + opts.proxy.name
|
||||
);
|
||||
|
||||
boost::system::error_code error{};
|
||||
proxy = ip::tcp::endpoint{ip::address::from_string(std::string{proxy_host}, error), port_value};
|
||||
THROW_WALLET_EXCEPTION_IF(bool(error), tools::error::wallet_internal_error, std::string{"Invalid IP address specified for --"} + opts.proxy.name);
|
||||
std::string{"Invalid address specified for --"} + opts.proxy.name);
|
||||
}
|
||||
|
||||
boost::optional<bool> trusted_daemon;
|
||||
@@ -1325,18 +1310,17 @@ bool wallet2::set_daemon(std::string daemon_address, boost::optional<epee::net_u
|
||||
return ret;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, boost::asio::ip::tcp::endpoint proxy, uint64_t upper_transaction_weight_limit, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options)
|
||||
bool wallet2::set_proxy(const std::string &address)
|
||||
{
|
||||
return m_http_client->set_proxy(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_checkpoints.init_default_checkpoints(m_nettype);
|
||||
m_is_initialized = true;
|
||||
m_upper_transaction_weight_limit = upper_transaction_weight_limit;
|
||||
if (proxy != boost::asio::ip::tcp::endpoint{})
|
||||
{
|
||||
epee::net_utils::http::abstract_http_client* abstract_http_client = m_http_client.get();
|
||||
epee::net_utils::http::http_simple_client* http_simple_client = dynamic_cast<epee::net_utils::http::http_simple_client*>(abstract_http_client);
|
||||
CHECK_AND_ASSERT_MES(http_simple_client != nullptr, false, "http_simple_client must be used to set proxy");
|
||||
http_simple_client->set_connector(net::socks::connector{std::move(proxy)});
|
||||
}
|
||||
return set_daemon(daemon_address, daemon_login, trusted_daemon, std::move(ssl_options));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#include "cryptonote_basic/account.h"
|
||||
#include "cryptonote_basic/account_boost_serialization.h"
|
||||
#include "cryptonote_basic/cryptonote_basic_impl.h"
|
||||
#include "net/http_client.h"
|
||||
#include "net/http.h"
|
||||
#include "storages/http_abstract_invoke.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||
@@ -269,7 +269,7 @@ private:
|
||||
static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds);
|
||||
static bool query_device(hw::device::device_type& device_type, const std::string& keys_file_name, const epee::wipeable_string& password, uint64_t kdf_rounds = 1);
|
||||
|
||||
wallet2(cryptonote::network_type nettype = cryptonote::MAINNET, uint64_t kdf_rounds = 1, bool unattended = false, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = std::unique_ptr<epee::net_utils::http::http_simple_client_factory>(new epee::net_utils::http::http_simple_client_factory()));
|
||||
wallet2(cryptonote::network_type nettype = cryptonote::MAINNET, uint64_t kdf_rounds = 1, bool unattended = false, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = std::unique_ptr<epee::net_utils::http::http_client_factory>(new net::http::client_factory()));
|
||||
~wallet2();
|
||||
|
||||
struct multisig_info
|
||||
@@ -753,13 +753,14 @@ private:
|
||||
bool deinit();
|
||||
bool init(std::string daemon_address = "http://localhost:8080",
|
||||
boost::optional<epee::net_utils::http::login> daemon_login = boost::none,
|
||||
boost::asio::ip::tcp::endpoint proxy = {},
|
||||
const std::string &proxy = "",
|
||||
uint64_t upper_transaction_weight_limit = 0,
|
||||
bool trusted_daemon = true,
|
||||
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);
|
||||
bool set_proxy(const std::string &address);
|
||||
|
||||
void stop() { m_run.store(false, std::memory_order_relaxed); m_message_store.stop(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user