net utl added
This commit is contained in:
parent
7237ac0e71
commit
2826f2e83f
4 changed files with 49 additions and 21 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
#include "https_call.h"
|
#include "net_utl.h"
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
|
|
@ -13,10 +13,17 @@ std::string resolveHostAddr(const std::string & hostName) {
|
||||||
auto query = ip::tcp::resolver::query(hostName, "");
|
auto query = ip::tcp::resolver::query(hostName, "");
|
||||||
auto iter = resolver.resolve(query);
|
auto iter = resolver.resolve(query);
|
||||||
auto endpoint = *iter;
|
auto endpoint = *iter;
|
||||||
auto addr = endpoint.address();
|
auto addr = ((ip::tcp::endpoint)endpoint).address();
|
||||||
return addr.to_string();
|
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
|
} // net
|
||||||
} // peerplays
|
} // peerplays
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace peerplays {
|
||||||
namespace net {
|
namespace net {
|
||||||
|
|
||||||
std::string resolveHostAddr(const std::string & hostName);
|
std::string resolveHostAddr(const std::string & hostName);
|
||||||
|
std::string stripProtoName(const std::string & utl);
|
||||||
|
|
||||||
|
|
||||||
} // net
|
} // net
|
||||||
} // peerplays
|
} // peerplays
|
||||||
|
|
|
||||||
|
|
@ -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 rpc_client::send_post_request(std::string body, bool show_log) {
|
||||||
|
|
||||||
fc::http::reply reply;
|
fc::http::reply reply;
|
||||||
auto temp = ip.substr(0, 6);
|
auto start = ip.substr(0, 6);
|
||||||
boost::algorithm::to_lower(temp);
|
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;
|
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;
|
std::string host;
|
||||||
|
|
||||||
if (temp == "http:/")
|
if (start == "http:/")
|
||||||
host = ip.substr(7);
|
host = ip.substr(7); // skip "http://"
|
||||||
else
|
else
|
||||||
host = ip;
|
host = ip;
|
||||||
|
|
||||||
fc::ip::endpoint endpoint;
|
std::string url = "http://" + host + ":" + std::to_string(port);
|
||||||
|
fc::ip::address addr;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
endpoint = fc::ip::endpoint(fc::ip::address(host), port));
|
addr = fc::ip::address(host);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
try {
|
try {
|
||||||
endpoint = fc::ip::endpoint(fc::ip::address(peerplays::net::resolveHostIp(host)), port));
|
addr = fc::ip::address(peerplays::net::resolveHostIp(host));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
if (show_log) {
|
if (show_log) {
|
||||||
std::string url = ip + ":" + std::to_string(port);
|
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;
|
try {
|
||||||
conn.connect_to(endpoint);
|
|
||||||
std::string url = "http://" + host + ":" + std::to_string(port);
|
|
||||||
|
|
||||||
//if (wallet.length() > 0) {
|
fc::http::connection conn;
|
||||||
// url = url + "/wallet/" + wallet;
|
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) {
|
if (show_log) {
|
||||||
ilog("### Request URL: ${url}", ("url", url));
|
ilog("### Request URL: ${url}", ("url", url));
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
#include <graphene/peerplays_sidechain/hive/transaction.hpp>
|
#include <graphene/peerplays_sidechain/hive/transaction.hpp>
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
|
|
||||||
|
#include "common/net_utl.h"
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
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) :
|
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;
|
private_keys[key_pair.first] = key_pair.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
fc::http::connection conn;
|
fc::http::connection conn;
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (fc::exception &e) {
|
||||||
elog("No Hive node running at ${ip} or wrong rpc port: ${port}", ("ip", node_ip)("port", node_rpc_port));
|
elog("No Hive node running at ${ip} or wrong rpc port: ${port}", ("ip", node_ip)("port", node_rpc_port));
|
||||||
FC_ASSERT(false);
|
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);
|
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();
|
std::string chain_id_str = node_rpc_client->get_chain_id();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue