diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/dns_utils.cpp | 16 | ||||
-rw-r--r-- | src/common/dns_utils.h | 7 | ||||
-rw-r--r-- | src/common/http_connection.h | 17 | ||||
-rw-r--r-- | src/common/rpc_client.h | 35 | ||||
-rw-r--r-- | src/common/unordered_containers_boost_serialization.h | 6 |
5 files changed, 20 insertions, 61 deletions
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 2efdcffcd..83259bc70 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -451,22 +451,6 @@ std::string get_account_address_as_str_from_url(const std::string& url, bool& dn return addresses[0]; } -bool get_account_address_from_str_or_url( - cryptonote::account_public_address& address - , bool& has_payment_id - , crypto::hash8& payment_id - , bool testnet - , const std::string& str_or_url - ) -{ - if (cryptonote::get_account_integrated_address_from_str(address, has_payment_id, payment_id, testnet, str_or_url)) - return true; - bool dnssec_valid; - std::string address_str = get_account_address_as_str_from_url(str_or_url, dnssec_valid); - return !address_str.empty() && - cryptonote::get_account_integrated_address_from_str(address, has_payment_id, payment_id, testnet, address_str); -} - } // namespace tools::dns_utils } // namespace tools diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index 5fe1d4775..8a63a8129 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -164,13 +164,6 @@ std::string address_from_txt_record(const std::string& s); std::vector<std::string> addresses_from_url(const std::string& url, bool& dnssec_valid); std::string get_account_address_as_str_from_url(const std::string& url, bool& dnssec_valid); -bool get_account_address_from_str_or_url( - cryptonote::account_public_address& address - , bool& has_payment_id - , crypto::hash8& payment_id - , bool testnet - , const std::string& str_or_url - ); } // namespace tools::dns_utils diff --git a/src/common/http_connection.h b/src/common/http_connection.h index 156474cdd..8a786361a 100644 --- a/src/common/http_connection.h +++ b/src/common/http_connection.h @@ -28,6 +28,7 @@ #pragma once +#include <chrono> #include "string_tools.h" #include "net/http_client.h" @@ -38,20 +39,16 @@ private: epee::net_utils::http::http_simple_client * mp_http_client; bool m_ok; public: - static unsigned int const TIMEOUT = 200000; + static constexpr std::chrono::seconds TIMEOUT() + { + return std::chrono::minutes(3) + std::chrono::seconds(30); + } - t_http_connection( - epee::net_utils::http::http_simple_client * p_http_client - , uint32_t ip - , uint16_t port - ) + t_http_connection(epee::net_utils::http::http_simple_client* p_http_client) : mp_http_client(p_http_client) , m_ok(false) { - // TODO fix http client so that it accepts properly typed arguments - std::string ip_str = epee::string_tools::get_ip_string_from_int32(ip); - std::string port_str = boost::lexical_cast<std::string>(port); - m_ok = mp_http_client->connect(ip_str, port_str, TIMEOUT); + m_ok = mp_http_client->connect(TIMEOUT()); } ~t_http_connection() diff --git a/src/common/rpc_client.h b/src/common/rpc_client.h index 9c0036198..f5ecc8b50 100644 --- a/src/common/rpc_client.h +++ b/src/common/rpc_client.h @@ -34,7 +34,6 @@ #include "storages/http_abstract_invoke.h" #include "net/http_client.h" #include "string_tools.h" -#include <boost/lexical_cast.hpp> namespace tools { @@ -42,27 +41,16 @@ namespace tools { private: epee::net_utils::http::http_simple_client m_http_client; - uint32_t m_ip; - uint16_t m_port; public: t_rpc_client( uint32_t ip , uint16_t port ) : m_http_client{} - , m_ip{ip} - , m_port{port} - {} - - std::string build_url(std::string const & relative_url) const { - std::string result = - "http://" - + epee::string_tools::get_ip_string_from_int32(m_ip) - + ":" - + boost::lexical_cast<std::string>(m_port) - + relative_url; - return result; + m_http_client.set_server( + epee::string_tools::get_ip_string_from_int32(ip), std::to_string(port) + ); } template <typename T_req, typename T_res> @@ -72,8 +60,7 @@ namespace tools , std::string const & method_name ) { - std::string rpc_url = build_url("/json_rpc"); - t_http_connection connection(&m_http_client, m_ip, m_port); + t_http_connection connection(&m_http_client); bool ok = connection.is_open(); if (!ok) @@ -81,7 +68,7 @@ namespace tools fail_msg_writer() << "Couldn't connect to daemon"; return false; } - ok = ok && epee::net_utils::invoke_http_json_rpc(rpc_url, method_name, req, res, m_http_client); + ok = ok && epee::net_utils::invoke_http_json_rpc("/json_rpc", method_name, req, res, m_http_client, t_http_connection::TIMEOUT()); if (!ok) { fail_msg_writer() << "Daemon request failed"; @@ -101,11 +88,10 @@ namespace tools , std::string const & fail_msg ) { - std::string rpc_url = build_url("/json_rpc"); - t_http_connection connection(&m_http_client, m_ip, m_port); + t_http_connection connection(&m_http_client); bool ok = connection.is_open(); - ok = ok && epee::net_utils::invoke_http_json_rpc(rpc_url, method_name, req, res, m_http_client); + ok = ok && epee::net_utils::invoke_http_json_rpc("/json_rpc", method_name, req, res, m_http_client, t_http_connection::TIMEOUT()); if (!ok) { fail_msg_writer() << "Couldn't connect to daemon"; @@ -130,11 +116,10 @@ namespace tools , std::string const & fail_msg ) { - std::string rpc_url = build_url(relative_url); - t_http_connection connection(&m_http_client, m_ip, m_port); + t_http_connection connection(&m_http_client); bool ok = connection.is_open(); - ok = ok && epee::net_utils::invoke_http_json_remote_command2(rpc_url, req, res, m_http_client); + ok = ok && epee::net_utils::invoke_http_json(relative_url, req, res, m_http_client, t_http_connection::TIMEOUT()); if (!ok) { fail_msg_writer() << "Couldn't connect to daemon"; @@ -153,7 +138,7 @@ namespace tools bool check_connection() { - t_http_connection connection(&m_http_client, m_ip, m_port); + t_http_connection connection(&m_http_client); return connection.is_open(); } }; diff --git a/src/common/unordered_containers_boost_serialization.h b/src/common/unordered_containers_boost_serialization.h index 08b5d9ccf..b2d5b27a6 100644 --- a/src/common/unordered_containers_boost_serialization.h +++ b/src/common/unordered_containers_boost_serialization.h @@ -43,7 +43,7 @@ namespace boost { size_t s = x.size(); a << s; - BOOST_FOREACH(auto& v, x) + for(auto& v: x) { a << v.first; a << v.second; @@ -72,7 +72,7 @@ namespace boost { size_t s = x.size(); a << s; - BOOST_FOREACH(auto& v, x) + for(auto& v: x) { a << v.first; a << v.second; @@ -101,7 +101,7 @@ namespace boost { size_t s = x.size(); a << s; - BOOST_FOREACH(auto& v, x) + for(auto& v: x) { a << v; } |