aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-12-08 23:45:04 +0200
committerRiccardo Spagni <ric@spagni.net>2016-12-08 23:45:04 +0200
commit12b59460c25b582366ea15ea642419b53d1d0897 (patch)
treed416989525ed742c78b840ab2df86f4b35eeec03 /src
parentMerge pull request #1415 (diff)
parentsimplewallet: restore automatically setting trusted local daemon (diff)
downloadmonero-12b59460c25b582366ea15ea642419b53d1d0897.tar.xz
Merge pull request #1417
0b91d825 simplewallet: restore automatically setting trusted local daemon (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/simplewallet/simplewallet.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index faeed31ce..d9c1bb4ed 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -949,6 +949,37 @@ void simple_wallet::print_seed(std::string seed)
std::cout << seed << std::endl;
}
//----------------------------------------------------------------------------------------------------
+static bool is_local_daemon(const std::string &address)
+{
+ // extract host
+ epee::net_utils::http::url_content u_c;
+ if (!epee::net_utils::parse_url(address, u_c))
+ {
+ LOG_PRINT_L1("Failed to determine whether daemon is local, assuming not");
+ return false;
+ }
+ if (u_c.host.empty())
+ {
+ LOG_PRINT_L1("Failed to determine whether daemon is local, assuming not");
+ return false;
+ }
+
+ // resolve to IP
+ boost::asio::io_service io_service;
+ boost::asio::ip::tcp::resolver resolver(io_service);
+ boost::asio::ip::tcp::resolver::query query(u_c.host, "");
+ boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query);
+ while (i != boost::asio::ip::tcp::resolver::iterator())
+ {
+ const boost::asio::ip::tcp::endpoint &ep = *i;
+ if (ep.address().is_loopback())
+ return true;
+ ++i;
+ }
+
+ return false;
+}
+//----------------------------------------------------------------------------------------------------
bool simple_wallet::init(const boost::program_options::variables_map& vm)
{
if (!handle_command_line(vm))
@@ -1158,6 +1189,18 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
CHECK_AND_ASSERT_MES(r, false, tr("failed to open account"));
}
assert(m_wallet);
+
+ // set --trusted-daemon if local
+ try
+ {
+ if (is_local_daemon(m_wallet->get_daemon_address()))
+ {
+ LOG_PRINT_L1(tr("Daemon is local, assuming trusted"));
+ m_trusted_daemon = true;
+ }
+ }
+ catch (const std::exception &e) { }
+
m_wallet->callback(this);
return true;
}