JSON RPC v2 support

This commit is contained in:
Antonio Juarez 2014-05-21 14:49:50 +01:00
parent d22ea471d9
commit 2b8558a48f
6 changed files with 75 additions and 49 deletions

View file

@ -1,3 +1,9 @@
Release notes 0.8.9
- JSON RPC v2.0 compatibility
- JSON RPC over TCP added
- Further optimizations
Release notes 0.8.8
- Fixed a bug with checkpoints behavior

View file

@ -267,23 +267,6 @@ namespace epee
if(0 == command.compare("exit") || 0 == command.compare("q"))
{
continue_handle = false;
}else if (!command.compare(0, 7, "set_log"))
{
//parse set_log command
if(command.size() != 9)
{
std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
continue;
}
uint16_t n = 0;
if(!string_tools::get_xtype_from_string(n, command.substr(8, 1)))
{
std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
continue;
}
log_space::get_set_log_detalisation_level(true, n);
std::cout << "New log level set " << n;
LOG_PRINT_L2("New log level set " << n);
}else if (command.empty())
{
continue;

View file

@ -25,6 +25,7 @@ namespace cryptonote {
ADD_CHECKPOINT(462250, "13468d210a5ec884cf839f0259f247ccf3efef0414ac45172033d32c739beb3e");
ADD_CHECKPOINT(468000, "251bcbd398b1f593193a7210934a3d87f692b2cb0c45206150f59683dd7e9ba1");
ADD_CHECKPOINT(480200, "363544ac9920c778b815c2fdbcbca70a0d79b21f662913a42da9b49e859f0e5b");
ADD_CHECKPOINT(484500, "5cdf2101a0a62a0ab2a1ca0c15a6212b21f6dbdc42a0b7c0bcf65ca40b7a14fb");
return true;
}

View file

@ -24,6 +24,7 @@
#include "p2p_networks.h"
#include "math_helper.h"
#include "net_node_common.h"
#include "common/command_line.h"
PUSH_WARNINGS
DISABLE_VS_WARNINGS(4355)
@ -146,6 +147,12 @@ namespace nodetool
bool make_expected_connections_count(bool white_list, size_t expected_connections);
bool is_priority_node(const net_address& na);
template <class Container>
bool connect_to_peerlist(const Container& peers);
template <class Container>
bool parse_peers_and_add_to_container(const boost::program_options::variables_map& vm, const command_line::arg_descriptor<std::vector<std::string> > & arg, Container& container);
//debug functions
std::string print_connections_container();
@ -190,6 +197,7 @@ namespace nodetool
uint64_t m_last_stat_request_time;
#endif
std::list<net_address> m_priority_peers;
std::vector<net_address> m_exclusive_peers;
std::vector<net_address> m_seed_nodes;
std::list<nodetool::peerlist_entry> m_command_line_peers;
uint64_t m_peer_livetime;

View file

@ -8,7 +8,6 @@
#include "version.h"
#include "string_tools.h"
#include "common/command_line.h"
#include "common/util.h"
#include "net/net_helper.h"
#include "math_helper.h"
@ -33,8 +32,11 @@ namespace nodetool
const command_line::arg_descriptor<bool> arg_p2p_allow_local_ip = {"allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes"};
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_peer = {"add-peer", "Manually add peer to local peerlist"};
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_priority_node = {"add-priority-node", "Specify list of peers to connect to and attempt to keep the connection open"};
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_exclusive_node = {"add-exclusive-node", "Specify list of peers to connect to only."
" If this option is given the options add-priority-node and seed-node are ignored"};
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_seed_node = {"seed-node", "Connect to a node to retrieve peer addresses, and disconnect"};
const command_line::arg_descriptor<bool> arg_p2p_hide_my_port = {"hide-my-port", "Do not announce yourself as peerlist candidate", false, true}; }
const command_line::arg_descriptor<bool> arg_p2p_hide_my_port = {"hide-my-port", "Do not announce yourself as peerlist candidate", false, true};
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
@ -46,6 +48,7 @@ namespace nodetool
command_line::add_arg(desc, arg_p2p_allow_local_ip);
command_line::add_arg(desc, arg_p2p_add_peer);
command_line::add_arg(desc, arg_p2p_add_priority_node);
command_line::add_arg(desc, arg_p2p_add_exclusive_node);
command_line::add_arg(desc, arg_p2p_seed_node);
command_line::add_arg(desc, arg_p2p_hide_my_port); }
//-----------------------------------------------------------------------------------
@ -122,30 +125,26 @@ namespace nodetool
}
}
if (command_line::has_arg(vm, arg_p2p_add_priority_node))
{
std::vector<std::string> perrs = command_line::get_arg(vm, arg_p2p_add_priority_node);
for(const std::string& pr_str: perrs)
{
nodetool::net_address na = AUTO_VAL_INIT(na);
bool r = parse_peer_from_string(na, pr_str);
CHECK_AND_ASSERT_MES(r, false, "Failed to parse address from string: " << pr_str);
m_priority_peers.push_back(na);
}
if (command_line::has_arg(vm,arg_p2p_add_exclusive_node))
{
if (!parse_peers_and_add_to_container(vm, arg_p2p_add_exclusive_node, m_exclusive_peers))
return false;
}
else if (command_line::has_arg(vm, arg_p2p_add_priority_node))
{
if (!parse_peers_and_add_to_container(vm, arg_p2p_add_priority_node, m_priority_peers))
return false;
}
if (command_line::has_arg(vm, arg_p2p_seed_node))
{
std::vector<std::string> seed_perrs = command_line::get_arg(vm, arg_p2p_seed_node);
for(const std::string& pr_str: seed_perrs)
{
nodetool::net_address na = AUTO_VAL_INIT(na);
bool r = parse_peer_from_string(na, pr_str);
CHECK_AND_ASSERT_MES(r, false, "Failed to parse seed address from string: " << pr_str);
m_seed_nodes.push_back(na);
}
if (!parse_peers_and_add_to_container(vm, arg_p2p_seed_node, m_seed_nodes))
return false;
}
if(command_line::has_arg(vm, arg_p2p_hide_my_port))
m_hide_my_port = true; return true;
m_hide_my_port = true;
return true;
}
//-----------------------------------------------------------------------------------
namespace
@ -628,6 +627,10 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::connections_maker()
{
if (!connect_to_peerlist(m_exclusive_peers)) return false;
if (!m_exclusive_peers.empty()) return true;
if(!m_peerlist.get_white_peers_count() && m_seed_nodes.size())
{
size_t try_count = 0;
@ -649,15 +652,7 @@ namespace nodetool
}
}
for(const net_address& na: m_priority_peers)
{
if(m_net_server.is_stop_signal_sent())
return false;
if(is_addr_connected(na))
continue;
try_to_connect_and_handshake_with_new_peer(na);
}
if (!connect_to_peerlist(m_priority_peers)) return false;
size_t expected_white_connections = (m_config.m_net_config.connections_count*P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT)/100;
@ -1124,6 +1119,39 @@ namespace nodetool
template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::is_priority_node(const net_address& na)
{
return std::find(m_priority_peers.begin(), m_priority_peers.end(), na) != m_priority_peers.end();
return (std::find(m_priority_peers.begin(), m_priority_peers.end(), na) != m_priority_peers.end()) || (std::find(m_exclusive_peers.begin(), m_exclusive_peers.end(), na) != m_exclusive_peers.end());
}
template<class t_payload_net_handler> template <class Container>
bool node_server<t_payload_net_handler>::connect_to_peerlist(const Container& peers)
{
for(const net_address& na: peers)
{
if(m_net_server.is_stop_signal_sent())
return false;
if(is_addr_connected(na))
continue;
try_to_connect_and_handshake_with_new_peer(na);
}
return true;
}
template<class t_payload_net_handler> template <class Container>
bool node_server<t_payload_net_handler>::parse_peers_and_add_to_container(const boost::program_options::variables_map& vm, const command_line::arg_descriptor<std::vector<std::string> > & arg, Container& container)
{
std::vector<std::string> perrs = command_line::get_arg(vm, arg);
for(const std::string& pr_str: perrs)
{
nodetool::net_address na = AUTO_VAL_INIT(na);
bool r = parse_peer_from_string(na, pr_str);
CHECK_AND_ASSERT_MES(r, false, "Failed to parse address from string: " << pr_str);
container.push_back(na);
}
return true;
}
}

View file

@ -1,4 +1,4 @@
#define BUILD_COMMIT_ID "@VERSION@"
#define PROJECT_VERSION "0.8.8"
#define PROJECT_VERSION "0.8.9"
#define PROJECT_VERSION_BUILD_NO "65"
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO "(" BUILD_COMMIT_ID ")"