Skip to content

Commit

Permalink
JSON RPC v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Juarez committed May 21, 2014
1 parent d22ea47 commit 2b8558a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 49 deletions.
6 changes: 6 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 0 additions & 17 deletions contrib/epee/include/console_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/cryptonote_core/checkpoints_create.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace cryptonote {
ADD_CHECKPOINT(462250, "13468d210a5ec884cf839f0259f247ccf3efef0414ac45172033d32c739beb3e");
ADD_CHECKPOINT(468000, "251bcbd398b1f593193a7210934a3d87f692b2cb0c45206150f59683dd7e9ba1");
ADD_CHECKPOINT(480200, "363544ac9920c778b815c2fdbcbca70a0d79b21f662913a42da9b49e859f0e5b");
ADD_CHECKPOINT(484500, "5cdf2101a0a62a0ab2a1ca0c15a6212b21f6dbdc42a0b7c0bcf65ca40b7a14fb");

return true;
}
Expand Down
8 changes: 8 additions & 0 deletions src/p2p/net_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
90 changes: 59 additions & 31 deletions src/p2p/net_node.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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>
Expand All @@ -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); }
//-----------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/version.h.in
Original file line number Diff line number Diff line change
@@ -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 ")"

0 comments on commit 2b8558a

Please sign in to comment.