diff --git a/libraries/plugins/peerplays_sidechain/common/net_utl.cpp b/libraries/plugins/peerplays_sidechain/common/net_utl.cpp index 81fe6673..d895193d 100644 --- a/libraries/plugins/peerplays_sidechain/common/net_utl.cpp +++ b/libraries/plugins/peerplays_sidechain/common/net_utl.cpp @@ -1,4 +1,4 @@ -#include "https_call.h" +#include "net_utl.h" #include @@ -13,10 +13,17 @@ std::string resolveHostAddr(const std::string & hostName) { auto query = ip::tcp::resolver::query(hostName, ""); auto iter = resolver.resolve(query); auto endpoint = *iter; - auto addr = endpoint.address(); + auto addr = ((ip::tcp::endpoint)endpoint).address(); return addr.to_string(); } +std::string stripProtoName(const std::string & url) { + auto index = url.find("://"); + if (index == url::npos) + return url; + return url.substr(index + 3); +} + } // net } // peerplays diff --git a/libraries/plugins/peerplays_sidechain/common/net_utl.h b/libraries/plugins/peerplays_sidechain/common/net_utl.h index 96c00dd5..d549fef3 100644 --- a/libraries/plugins/peerplays_sidechain/common/net_utl.h +++ b/libraries/plugins/peerplays_sidechain/common/net_utl.h @@ -6,6 +6,8 @@ namespace peerplays { namespace net { std::string resolveHostAddr(const std::string & hostName); +std::string stripProtoName(const std::string & utl); + } // net } // peerplays diff --git a/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp b/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp index 6f7a7b26..32edfc2d 100644 --- a/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp +++ b/libraries/plugins/peerplays_sidechain/common/rpc_client.cpp @@ -105,12 +105,12 @@ std::string rpc_client::send_post_request(std::string method, std::string params fc::http::reply rpc_client::send_post_request(std::string body, bool show_log) { fc::http::reply reply; - auto temp = ip.substr(0, 6); - boost::algorithm::to_lower(temp); + auto start = ip.substr(0, 6); + boost::algorithm::to_lower(start); - if (temp == "https:") { + if (start == "https:") { - auto host = ip.substr(8); + auto host = ip.substr(8); // skip "https://" using namespace peerplays::net; @@ -140,18 +140,19 @@ fc::http::reply rpc_client::send_post_request(std::string body, bool show_log) { std::string host; - if (temp == "http:/") - host = ip.substr(7); + if (start == "http:/") + host = ip.substr(7); // skip "http://" else host = ip; - fc::ip::endpoint endpoint; + std::string url = "http://" + host + ":" + std::to_string(port); + fc::ip::address addr; try { - endpoint = fc::ip::endpoint(fc::ip::address(host), port)); + addr = fc::ip::address(host); } catch (...) { try { - endpoint = fc::ip::endpoint(fc::ip::address(peerplays::net::resolveHostIp(host)), port)); + addr = fc::ip::address(peerplays::net::resolveHostIp(host)); } catch (...) { if (show_log) { std::string url = ip + ":" + std::to_string(port); @@ -163,15 +164,19 @@ fc::http::reply rpc_client::send_post_request(std::string body, bool show_log) { } } - fc::http::connection conn; - conn.connect_to(endpoint); - std::string url = "http://" + host + ":" + std::to_string(port); + try { - //if (wallet.length() > 0) { - // url = url + "/wallet/" + wallet; - //} + fc::http::connection conn; + conn.connect_to(fc::ip::endpoint(addr, port)); - reply = conn.request("POST", url, body, fc::http::headers{authorization}); + //if (wallet.length() > 0) { + // url = url + "/wallet/" + wallet; + //} + + reply = conn.request("POST", url, body, fc::http::headers{authorization}); + + } catch (...) { + } if (show_log) { ilog("### Request URL: ${url}", ("url", url)); diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp index ac96da16..8e270c4c 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_hive.cpp @@ -28,6 +28,8 @@ #include #include +#include "common/net_utl.h" + namespace graphene { namespace peerplays_sidechain { hive_node_rpc_client::hive_node_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls) : @@ -144,16 +146,28 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi private_keys[key_pair.first] = key_pair.second; } } -/* + fc::http::connection conn; try { - conn.connect_to(fc::ip::endpoint(fc::ip::address(node_ip), node_rpc_port)); + auto host = peerplays::net::stripProtoName(node_ip); + fc::ip::address addr; + try { + addr = fc::ip::address(host); + } catch (...) { + try { + addr = fc::ip::address(peerplays::net::resolveHostIp(host)); + } catch (...) { + elog("Failed to resolve Hive node address ${ip}", ("ip", node_ip)); + FC_ASSERT(false); + } + } + conn.connect_to(fc::ip::endpoint(addr, node_rpc_port)); } catch (fc::exception &e) { elog("No Hive node running at ${ip} or wrong rpc port: ${port}", ("ip", node_ip)("port", node_rpc_port)); FC_ASSERT(false); } -*/ + node_rpc_client = new hive_node_rpc_client(node_ip, node_rpc_port, node_rpc_user, node_rpc_password, debug_rpc_calls); std::string chain_id_str = node_rpc_client->get_chain_id();