mirror of https://github.com/oxen-io/oxen-core.git
Remove p2p rpc_port; p2p code clean-ups
The public rpc port code from Monero is not used on Oxen (we have no ability to enable it because we didn't want it), but still carried around and printed pointlessly. This removes it entirely. Along the way I ran into some really nasty p2p code using templates for absolutely no reason at all, so I fixed that crap, and moved some p2p serialization out of headers into a .cpp file. (This only scratches the surface, but as we're going to replace the p2p code entirely eventually I don't want to waste time trying to polish a turd).
This commit is contained in:
parent
6c54ca6abd
commit
7551f5c137
|
@ -63,7 +63,6 @@ namespace cryptonote
|
|||
epee::copyable_atomic m_callback_request_count{0}; //in debug purpose: problem with double callback rise
|
||||
crypto::hash m_last_known_hash{crypto::null_hash};
|
||||
uint32_t m_pruning_seed{0};
|
||||
uint16_t m_rpc_port{0};
|
||||
bool m_anchor{false};
|
||||
//size_t m_score{0}; TODO: add score calculations
|
||||
};
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "cryptonote_basic/miner.h"
|
||||
#include "epee/misc_language.h"
|
||||
#include "epee/int-util.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "common/threadpool.h"
|
||||
#include "common/boost_serialization_helper.h"
|
||||
#include "epee/warnings.h"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "uptime_proof.h"
|
||||
#include "service_node_list.h"
|
||||
#include "common/string_util.h"
|
||||
#include "epee/string_tools.h"
|
||||
#include "version.h"
|
||||
|
||||
extern "C"
|
||||
|
|
|
@ -63,7 +63,6 @@ namespace cryptonote
|
|||
std::string host;
|
||||
std::string ip;
|
||||
std::string port;
|
||||
uint16_t rpc_port;
|
||||
|
||||
std::string peer_id;
|
||||
|
||||
|
|
|
@ -62,9 +62,8 @@ namespace cryptonote
|
|||
class t_cryptonote_protocol_handler: public i_cryptonote_protocol
|
||||
{
|
||||
public:
|
||||
typedef cryptonote_connection_context connection_context;
|
||||
typedef t_cryptonote_protocol_handler<t_core> cryptonote_protocol_handler;
|
||||
typedef CORE_SYNC_DATA payload_type;
|
||||
using connection_context = cryptonote_connection_context;
|
||||
using cryptonote_protocol_handler = t_cryptonote_protocol_handler<t_core>;
|
||||
|
||||
t_cryptonote_protocol_handler(t_core& rcore, bool offline = false);
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ namespace cryptonote
|
|||
seconds_f connection_time{now - cntxt.m_started};
|
||||
ss << std::setw(30) << std::left << std::string(cntxt.m_is_income ? " [INC]":"[OUT]") +
|
||||
cntxt.m_remote_address.str()
|
||||
<< std::setw(20) << nodetool::peerid_to_string(peer_id)
|
||||
<< std::setw(20) << fmt::format("{:016x}", peer_id)
|
||||
<< std::setw(30) << std::to_string(cntxt.m_recv_cnt) + "(" + std::to_string(tools::to_seconds(now - cntxt.m_last_recv)) + ")" +
|
||||
"/" + std::to_string(cntxt.m_send_cnt) + "(" + std::to_string(tools::to_seconds(now - cntxt.m_last_send)) + ")"
|
||||
<< std::setw(25) << get_protocol_state_string(cntxt.m_state)
|
||||
|
@ -286,9 +286,7 @@ namespace cryptonote
|
|||
cnx.ip = cnx.host;
|
||||
cnx.port = std::to_string(cntxt.m_remote_address.as<epee::net_utils::ipv4_network_address>().port());
|
||||
}
|
||||
cnx.rpc_port = cntxt.m_rpc_port;
|
||||
|
||||
cnx.peer_id = nodetool::peerid_to_string(peer_id);
|
||||
cnx.peer_id = fmt::format("{:016x}", peer_id);
|
||||
|
||||
cnx.live_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - cntxt.m_started);
|
||||
cnx.recv_idle_time = std::chrono::duration_cast<std::chrono::milliseconds>(now - std::max(cntxt.m_started, cntxt.m_last_recv));
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "common/command_line.h"
|
||||
#include "common/hex.h"
|
||||
#include "common/scoped_message_writer.h"
|
||||
#include "common/string_util.h"
|
||||
#include "version.h"
|
||||
#include "daemon/command_parser_executor.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
|
@ -121,44 +122,29 @@ bool command_parser_executor::print_sn_state_changes(const std::vector<std::stri
|
|||
|
||||
bool command_parser_executor::print_peer_list(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.size() > 3)
|
||||
{
|
||||
std::cout << "use: print_pl [white] [gray] [<limit>] [pruned] [publicrpc]" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool white = false;
|
||||
bool gray = false;
|
||||
bool pruned = false;
|
||||
bool publicrpc = false;
|
||||
size_t limit = 0;
|
||||
for (size_t i = 0; i < args.size(); ++i)
|
||||
for (const auto& arg : args)
|
||||
{
|
||||
if (args[i] == "white")
|
||||
{
|
||||
if (arg == "white")
|
||||
white = true;
|
||||
}
|
||||
else if (args[i] == "gray")
|
||||
{
|
||||
else if (arg == "gray")
|
||||
gray = true;
|
||||
}
|
||||
else if (args[i] == "pruned")
|
||||
{
|
||||
else if (arg == "pruned")
|
||||
pruned = true;
|
||||
}
|
||||
else if (args[i] == "publicrpc")
|
||||
{
|
||||
publicrpc = true;
|
||||
}
|
||||
else if (!epee::string_tools::get_xtype_from_string(limit, args[i]))
|
||||
{
|
||||
std::cout << "unexpected argument: " << args[i] << std::endl;
|
||||
else if (tools::parse_int(arg, limit))
|
||||
/*limit already set*/;
|
||||
else {
|
||||
std::cout << "Unexpected argument: " << arg << "\n";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const bool print_both = !white && !gray;
|
||||
return m_executor.print_peer_list(white | print_both, gray | print_both, limit, pruned, publicrpc);
|
||||
if (!white && !gray)
|
||||
white = gray = true;
|
||||
return m_executor.print_peer_list(white, gray, limit, pruned);
|
||||
}
|
||||
|
||||
bool command_parser_executor::print_peer_list_stats(const std::vector<std::string>& args)
|
||||
|
|
|
@ -54,7 +54,7 @@ void command_server::init_commands(cryptonote::rpc::core_rpc_server* rpc_server)
|
|||
m_command_lookup.set_handler(
|
||||
"print_pl"
|
||||
, [this](const auto &x) { return m_parser.print_peer_list(x); }
|
||||
, "print_pl [white] [gray] [pruned] [publicrpc] [<limit>]"
|
||||
, "print_pl [white] [gray] [pruned] [<limit>]"
|
||||
, "Print the current peer list."
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
|
@ -135,13 +135,8 @@ void command_server::init_commands(cryptonote::rpc::core_rpc_server* rpc_server)
|
|||
m_command_lookup.set_handler(
|
||||
"start_mining"
|
||||
, [this](const auto &x) { return m_parser.start_mining(x); }
|
||||
#if defined NDEBUG
|
||||
, "start_mining <addr> [threads=(<threads>|auto)"
|
||||
, "Start mining for specified address. Defaults to 1 thread; use \"auto\" to autodetect optimal number of threads."
|
||||
#else
|
||||
, "start_mining <addr> [threads=(<threads>|auto) [num_blocks=<num>]"
|
||||
, "Start mining for specified address. Defaults to 1 thread; use \"auto\" to autodetect optimal number of threads. When num_blocks is set, continue mining until the (current_height + num_blocks) is met, irrespective of if this Daemon found those block(s) or not."
|
||||
#endif
|
||||
, "start_mining <addr> [threads=N] [num_blocks=B]"
|
||||
, "Start mining for specified address, primarily for debug and testing purposes as Oxen is proof-of-stake. Defaults to 1 thread. When num_blocks is set, continue mining until the blockchain reaches height (current + B)."
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"stop_mining"
|
||||
|
@ -333,8 +328,7 @@ or "default" to return the limit to its default value.)"
|
|||
"set_bootstrap_daemon"
|
||||
, [this](const auto &x) { return m_parser.set_bootstrap_daemon(x); }
|
||||
, "set_bootstrap_daemon (auto | none | host[:port] [username] [password])"
|
||||
, "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced.\n"
|
||||
"Use 'auto' to enable automatic public nodes discovering and bootstrap daemon switching"
|
||||
, "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced."
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"flush_cache"
|
||||
|
|
|
@ -161,14 +161,11 @@ namespace {
|
|||
return get_human_time_ago(std::chrono::seconds{now - t}, abbreviate);
|
||||
}
|
||||
|
||||
bool print_peer(std::string_view prefix, const json& peer, bool pruned_only, bool publicrpc_only)
|
||||
bool print_peer(std::string_view prefix, const json& peer, bool pruned_only)
|
||||
{
|
||||
auto pruning_seed = peer.value<uint64_t>("pruning_seed", 0);
|
||||
if (pruned_only && pruning_seed == 0)
|
||||
return false;
|
||||
auto rpc_port = peer.value<uint16_t>("rpc_port", 0);
|
||||
if (publicrpc_only && rpc_port == 0)
|
||||
return false;
|
||||
|
||||
time_t now = std::time(nullptr);
|
||||
time_t last_seen = peer.value<time_t>("last_seen", 0);
|
||||
|
@ -346,7 +343,7 @@ bool rpc_command_executor::print_sn_state_changes(uint64_t start_height, uint64_
|
|||
return true;
|
||||
}
|
||||
|
||||
bool rpc_command_executor::print_peer_list(bool white, bool gray, size_t limit, bool pruned_only, bool publicrpc_only) {
|
||||
bool rpc_command_executor::print_peer_list(bool white, bool gray, size_t limit, bool pruned_only) {
|
||||
auto maybe_pl = try_running([this] { return invoke<GET_PEER_LIST>(); }, "Failed to retrieve peer list");
|
||||
if (!maybe_pl)
|
||||
return false;
|
||||
|
@ -355,11 +352,11 @@ bool rpc_command_executor::print_peer_list(bool white, bool gray, size_t limit,
|
|||
if (!limit) limit = std::numeric_limits<size_t>::max();
|
||||
if (white) {
|
||||
tools::success_msg_writer() << pl["white_list"].size() << " whitelist peers:";
|
||||
print_peers("white", pl["white_list"], limit, pruned_only, publicrpc_only);
|
||||
print_peers("white", pl["white_list"], limit, pruned_only);
|
||||
}
|
||||
if (gray) {
|
||||
tools::success_msg_writer() << pl["gray_list"].size() << " graylist peers:";
|
||||
print_peers("gray", pl["gray_list"], limit, pruned_only, publicrpc_only);
|
||||
print_peers("gray", pl["gray_list"], limit, pruned_only);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
|
||||
bool print_sn_state_changes(uint64_t start_height, uint64_t end_height);
|
||||
|
||||
bool print_peer_list(bool white = true, bool gray = true, size_t limit = 0, bool pruned_only = false, bool publicrpc_only = false);
|
||||
bool print_peer_list(bool white = true, bool gray = true, size_t limit = 0, bool pruned_only = false);
|
||||
|
||||
bool print_peer_list_stats();
|
||||
|
||||
|
|
|
@ -95,8 +95,6 @@ int main(int argc, char* argv[])
|
|||
SL(nodetool::anchor_peerlist_entry);
|
||||
SL(nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core>>);
|
||||
SL(nodetool::p2p_connection_context_t<cryptonote::t_cryptonote_protocol_handler<cryptonote::core>::connection_context>);
|
||||
SL(nodetool::network_address_old);
|
||||
SL(nodetool::peerlist_entry_base<nodetool::network_address_old>);
|
||||
|
||||
SL(nodetool::network_config);
|
||||
SL(nodetool::basic_node_data);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
add_library(p2p
|
||||
p2p_protocol_defs.cpp
|
||||
net_node.cpp
|
||||
net_node.inl
|
||||
net_peerlist.cpp
|
||||
|
|
|
@ -293,8 +293,8 @@ namespace nodetool
|
|||
{
|
||||
switch (command)
|
||||
{
|
||||
case nodetool::COMMAND_HANDSHAKE_T<cryptonote::CORE_SYNC_DATA>::ID:
|
||||
case nodetool::COMMAND_TIMED_SYNC_T<cryptonote::CORE_SYNC_DATA>::ID:
|
||||
case nodetool::COMMAND_HANDSHAKE::ID:
|
||||
case nodetool::COMMAND_TIMED_SYNC::ID:
|
||||
case cryptonote::NOTIFY_NEW_TRANSACTIONS::ID:
|
||||
return false;
|
||||
default:
|
||||
|
|
|
@ -124,12 +124,9 @@ namespace nodetool
|
|||
struct by_peer_id{};
|
||||
struct by_addr{};
|
||||
|
||||
typedef p2p_connection_context_t<typename t_payload_net_handler::connection_context> p2p_connection_context;
|
||||
using p2p_connection_context = p2p_connection_context_t<typename t_payload_net_handler::connection_context>;
|
||||
|
||||
typedef COMMAND_HANDSHAKE_T<typename t_payload_net_handler::payload_type> COMMAND_HANDSHAKE;
|
||||
typedef COMMAND_TIMED_SYNC_T<typename t_payload_net_handler::payload_type> COMMAND_TIMED_SYNC;
|
||||
|
||||
typedef epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<p2p_connection_context>> net_server;
|
||||
using net_server = epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<p2p_connection_context>>;
|
||||
|
||||
struct network_zone;
|
||||
using connect_func = std::optional<p2p_connection_context>(network_zone&, epee::net_utils::network_address const&);
|
||||
|
@ -221,7 +218,6 @@ namespace nodetool
|
|||
node_server(t_payload_net_handler& payload_handler)
|
||||
: m_payload_handler(payload_handler),
|
||||
m_external_port(0),
|
||||
m_rpc_port(0),
|
||||
m_allow_local_ip(false),
|
||||
m_hide_my_port(false),
|
||||
m_igd(no_igd),
|
||||
|
@ -403,11 +399,6 @@ namespace nodetool
|
|||
|
||||
public:
|
||||
|
||||
void set_rpc_port(uint16_t rpc_port)
|
||||
{
|
||||
m_rpc_port = rpc_port;
|
||||
}
|
||||
|
||||
void reset_peer_handshake_timer()
|
||||
{
|
||||
m_peer_handshake_idle_maker_interval.reset();
|
||||
|
@ -421,7 +412,6 @@ namespace nodetool
|
|||
uint32_t m_listening_port;
|
||||
uint32_t m_listening_port_ipv6;
|
||||
uint32_t m_external_port;
|
||||
uint16_t m_rpc_port;
|
||||
bool m_allow_local_ip;
|
||||
bool m_hide_my_port;
|
||||
igd_t m_igd;
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "cryptonote_config.h"
|
||||
#include "version.h"
|
||||
#include "epee/string_tools.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "common/file.h"
|
||||
#include "common/dns_utils.h"
|
||||
#include "common/pruning.h"
|
||||
|
@ -57,6 +58,8 @@
|
|||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "net/parse.h"
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#ifndef WITHOUT_MINIUPNPC
|
||||
#include <miniupnp/miniupnpc/miniupnpc.h>
|
||||
#include <miniupnp/miniupnpc/upnpcommands.h>
|
||||
|
@ -994,9 +997,8 @@ namespace nodetool
|
|||
}
|
||||
|
||||
pi = context.peer_id = rsp.node_data.peer_id;
|
||||
context.m_rpc_port = rsp.node_data.rpc_port;
|
||||
network_zone& zone = m_network_zones.at(context.m_remote_address.get_zone());
|
||||
zone.m_peerlist.set_peer_just_seen(rsp.node_data.peer_id, context.m_remote_address, context.m_pruning_seed, context.m_rpc_port);
|
||||
zone.m_peerlist.set_peer_just_seen(rsp.node_data.peer_id, context.m_remote_address, context.m_pruning_seed);
|
||||
|
||||
// move
|
||||
if(rsp.node_data.peer_id == zone.m_config.m_peer_id)
|
||||
|
@ -1053,7 +1055,7 @@ namespace nodetool
|
|||
add_host_fail(context.m_remote_address);
|
||||
}
|
||||
if(!context.m_is_income)
|
||||
m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.set_peer_just_seen(context.peer_id, context.m_remote_address, context.m_pruning_seed, context.m_rpc_port);
|
||||
m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.set_peer_just_seen(context.peer_id, context.m_remote_address, context.m_pruning_seed);
|
||||
if (!m_payload_handler.process_payload_sync_data(std::move(rsp.payload_data), context, false))
|
||||
{
|
||||
m_network_zones.at(context.m_remote_address.get_zone()).m_net_server.get_config_object().close(context.m_connection_id );
|
||||
|
@ -1221,7 +1223,6 @@ namespace nodetool
|
|||
time(&last_seen);
|
||||
pe_local.last_seen = static_cast<int64_t>(last_seen);
|
||||
pe_local.pruning_seed = con->m_pruning_seed;
|
||||
pe_local.rpc_port = con->m_rpc_port;
|
||||
zone.m_peerlist.append_with_peer_white(pe_local);
|
||||
//update last seen and push it to peerlist manager
|
||||
|
||||
|
@ -1299,6 +1300,12 @@ namespace nodetool
|
|||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string peerid_to_string(peerid_type peer_id)
|
||||
{
|
||||
return fmt::format("{:016x}", peer_id);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::make_new_connection_from_anchor_peerlist(const std::vector<anchor_peerlist_entry>& anchor_peerlist)
|
||||
|
@ -1838,8 +1845,6 @@ namespace nodetool
|
|||
const epee::net_utils::ipv4_network_address &ipv4 = na.as<const epee::net_utils::ipv4_network_address>();
|
||||
if (ipv4.ip() == 0)
|
||||
ignore = true;
|
||||
else if (ipv4.port() == be.rpc_port)
|
||||
ignore = true;
|
||||
}
|
||||
if (be.pruning_seed && (be.pruning_seed < tools::make_pruning_seed(1, CRYPTONOTE_PRUNING_LOG_STRIPES) || be.pruning_seed > tools::make_pruning_seed(1ul << CRYPTONOTE_PRUNING_LOG_STRIPES, CRYPTONOTE_PRUNING_LOG_STRIPES)))
|
||||
ignore = true;
|
||||
|
@ -1890,7 +1895,6 @@ namespace nodetool
|
|||
node_data.my_port = m_external_port ? m_external_port : m_listening_port;
|
||||
else
|
||||
node_data.my_port = 0;
|
||||
node_data.rpc_port = zone.m_can_pingback ? m_rpc_port : 0;
|
||||
node_data.network_id = m_network_id;
|
||||
return true;
|
||||
}
|
||||
|
@ -2096,7 +2100,7 @@ namespace nodetool
|
|||
}
|
||||
|
||||
network_zone& zone = m_network_zones.at(address.get_zone());
|
||||
if(rsp.status != PING_OK_RESPONSE_STATUS_TEXT || pr != rsp.peer_id)
|
||||
if(rsp.status != COMMAND_PING::OK_RESPONSE || pr != rsp.peer_id)
|
||||
{
|
||||
LOG_WARNING_CC(ping_context, "back ping invoke wrong response \"" << rsp.status << "\" from" << address.str() << ", hsh_peer_id=" << pr_ << ", rsp.peer_id=" << peerid_to_string(rsp.peer_id));
|
||||
zone.m_net_server.get_config_object().close(ping_context.m_connection_id);
|
||||
|
@ -2225,7 +2229,6 @@ namespace nodetool
|
|||
//associate peer_id with this connection
|
||||
context.peer_id = arg.node_data.peer_id;
|
||||
context.m_in_timedsync = false;
|
||||
context.m_rpc_port = arg.node_data.rpc_port;
|
||||
|
||||
if(arg.node_data.my_port && zone.m_can_pingback)
|
||||
{
|
||||
|
@ -2252,7 +2255,6 @@ namespace nodetool
|
|||
pe.last_seen = static_cast<int64_t>(last_seen);
|
||||
pe.id = peer_id_l;
|
||||
pe.pruning_seed = context.m_pruning_seed;
|
||||
pe.rpc_port = context.m_rpc_port;
|
||||
this->m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.append_with_peer_white(pe);
|
||||
LOG_DEBUG_CC(context, "PING SUCCESS " << context.m_remote_address.host_str() << ":" << port_l);
|
||||
});
|
||||
|
@ -2272,7 +2274,7 @@ namespace nodetool
|
|||
int node_server<t_payload_net_handler>::handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, p2p_connection_context& context)
|
||||
{
|
||||
LOG_DEBUG_CC(context, "COMMAND_PING");
|
||||
rsp.status = PING_OK_RESPONSE_STATUS_TEXT;
|
||||
rsp.status = COMMAND_PING::OK_RESPONSE;
|
||||
rsp.peer_id = m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_peer_id;
|
||||
return 1;
|
||||
}
|
||||
|
@ -2567,7 +2569,7 @@ namespace nodetool
|
|||
}
|
||||
else
|
||||
{
|
||||
zone.second.m_peerlist.set_peer_just_seen(pe.id, pe.adr, pe.pruning_seed, pe.rpc_port);
|
||||
zone.second.m_peerlist.set_peer_just_seen(pe.id, pe.adr, pe.pruning_seed);
|
||||
LOG_PRINT_L2("PEER PROMOTED TO WHITE PEER LIST IP address: " << pe.adr.host_str() << " Peer ID: " << peerid_to_string(pe.id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace nodetool
|
|||
bool append_with_peer_white(const peerlist_entry& pr);
|
||||
bool append_with_peer_gray(const peerlist_entry& pr);
|
||||
bool append_with_peer_anchor(const anchor_peerlist_entry& ple);
|
||||
bool set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address& addr, uint32_t pruning_seed, uint16_t rpc_port);
|
||||
bool set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address& addr, uint32_t pruning_seed);
|
||||
bool is_host_allowed(const epee::net_utils::network_address &address);
|
||||
bool get_random_gray_peer(peerlist_entry& pe);
|
||||
bool remove_from_peer_gray(const peerlist_entry& pe);
|
||||
|
@ -317,7 +317,7 @@ namespace nodetool
|
|||
}
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
bool peerlist_manager::set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address& addr, uint32_t pruning_seed, uint16_t rpc_port)
|
||||
bool peerlist_manager::set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address& addr, uint32_t pruning_seed)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
std::lock_guard lock{m_peerlist_lock};
|
||||
|
@ -327,7 +327,6 @@ namespace nodetool
|
|||
ple.id = peer;
|
||||
ple.last_seen = time(NULL);
|
||||
ple.pruning_seed = pruning_seed;
|
||||
ple.rpc_port = rpc_port;
|
||||
return append_with_peer_white(ple);
|
||||
CATCH_ENTRY_L0("peerlist_manager::set_peer_just_seen()", false);
|
||||
}
|
||||
|
@ -353,8 +352,6 @@ namespace nodetool
|
|||
peerlist_entry new_ple = ple;
|
||||
if (by_addr_it_wt->pruning_seed && ple.pruning_seed == 0) // guard against older nodes not passing pruning info around
|
||||
new_ple.pruning_seed = by_addr_it_wt->pruning_seed;
|
||||
if (by_addr_it_wt->rpc_port && ple.rpc_port == 0) // guard against older nodes not passing RPC port around
|
||||
new_ple.rpc_port = by_addr_it_wt->rpc_port;
|
||||
new_ple.last_seen = by_addr_it_wt->last_seen; // do not overwrite the last seen timestamp, incoming peer list are untrusted
|
||||
m_peers_white.replace(by_addr_it_wt, new_ple);
|
||||
}
|
||||
|
@ -394,8 +391,6 @@ namespace nodetool
|
|||
peerlist_entry new_ple = ple;
|
||||
if (by_addr_it_gr->pruning_seed && ple.pruning_seed == 0) // guard against older nodes not passing pruning info around
|
||||
new_ple.pruning_seed = by_addr_it_gr->pruning_seed;
|
||||
if (by_addr_it_gr->rpc_port && ple.rpc_port == 0) // guard against older nodes not passing RPC port around
|
||||
new_ple.rpc_port = by_addr_it_gr->rpc_port;
|
||||
new_ple.last_seen = by_addr_it_gr->last_seen; // do not overwrite the last seen timestamp, incoming peer list are untrusted
|
||||
m_peers_gray.replace(by_addr_it_gr, new_ple);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "common/pruning.h"
|
||||
#endif
|
||||
|
||||
BOOST_CLASS_VERSION(nodetool::peerlist_entry, 2)
|
||||
BOOST_CLASS_VERSION(nodetool::peerlist_entry, 3)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
@ -236,11 +236,15 @@ namespace boost
|
|||
#endif
|
||||
if (ver < 2)
|
||||
{
|
||||
if (!typename Archive::is_saving())
|
||||
pl.rpc_port = 0;
|
||||
return;
|
||||
}
|
||||
a & pl.rpc_port;
|
||||
|
||||
if (ver < 3)
|
||||
{
|
||||
// Unused, but don't break
|
||||
uint16_t rpc_port = 0;
|
||||
a & rpc_port;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Archive, class ver_type>
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
#include "p2p_protocol_defs.h"
|
||||
#include "epee/misc_language.h"
|
||||
#include "epee/string_tools.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "net/tor_address.h" // needed for serialization
|
||||
#include "net/i2p_address.h" // needed for serialization
|
||||
#include <fmt/core.h>
|
||||
|
||||
namespace nodetool {
|
||||
|
||||
std::string print_peerlist_to_string(const std::vector<peerlist_entry>& pl)
|
||||
{
|
||||
time_t now = time(nullptr);
|
||||
std::string result;
|
||||
for (const auto& pe : pl) {
|
||||
result += fmt::format("{:016x}\t{}\tpruning seed {}\tlast_seen {}",
|
||||
pe.id, pe.adr.str(), pe.pruning_seed,
|
||||
(pe.last_seen == 0 ? std::string("never") : epee::misc_utils::get_time_interval_string(now - pe.last_seen)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(peerlist_entry)
|
||||
KV_SERIALIZE(adr)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE_OPT(last_seen, (int64_t)0)
|
||||
KV_SERIALIZE_OPT(pruning_seed, (uint32_t)0)
|
||||
// rpc_port is unused, but pass it along anyway to avoid breaking the protocol
|
||||
uint16_t rpc_port = 0;
|
||||
KV_SERIALIZE_VALUE(rpc_port);
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(anchor_peerlist_entry)
|
||||
KV_SERIALIZE(adr)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(first_seen)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(connection_entry)
|
||||
KV_SERIALIZE(adr)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(is_income)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(network_config)
|
||||
KV_SERIALIZE(max_out_connection_count)
|
||||
KV_SERIALIZE(max_in_connection_count)
|
||||
KV_SERIALIZE(handshake_interval)
|
||||
KV_SERIALIZE(packet_max_size)
|
||||
KV_SERIALIZE(config_id)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(basic_node_data)
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB(network_id)
|
||||
KV_SERIALIZE(peer_id)
|
||||
KV_SERIALIZE(my_port)
|
||||
// Unused, but pass a 0 to avoid breaking the protocol
|
||||
uint16_t rpc_port = 0;
|
||||
KV_SERIALIZE_VALUE(rpc_port);
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_HANDSHAKE::request)
|
||||
KV_SERIALIZE(node_data)
|
||||
KV_SERIALIZE(payload_data)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_HANDSHAKE::response)
|
||||
KV_SERIALIZE(node_data)
|
||||
KV_SERIALIZE(payload_data)
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_TIMED_SYNC::request)
|
||||
KV_SERIALIZE(payload_data)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_TIMED_SYNC::response)
|
||||
KV_SERIALIZE(payload_data)
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_PING::request)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_PING::response)
|
||||
KV_SERIALIZE(status)
|
||||
KV_SERIALIZE(peer_id)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_REQUEST_SUPPORT_FLAGS::request)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
|
||||
KV_SERIALIZE_MAP_CODE_BEGIN(COMMAND_REQUEST_SUPPORT_FLAGS::response)
|
||||
KV_SERIALIZE(support_flags)
|
||||
KV_SERIALIZE_MAP_CODE_END()
|
||||
}
|
|
@ -31,122 +31,51 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/serialization/version.hpp>
|
||||
#include "epee/serialization/keyvalue_serialization.h"
|
||||
#include "epee/net/net_utils_base.h"
|
||||
#include "net/tor_address.h" // needed for serialization
|
||||
#include "net/i2p_address.h" // needed for serialization
|
||||
#include "epee/misc_language.h"
|
||||
#include "epee/string_tools.h"
|
||||
#include "epee/time_helper.h"
|
||||
#include "cryptonote_config.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "cryptonote_protocol/cryptonote_protocol_defs.h"
|
||||
|
||||
namespace nodetool
|
||||
{
|
||||
typedef boost::uuids::uuid uuid;
|
||||
typedef uint64_t peerid_type;
|
||||
|
||||
static inline std::string peerid_to_string(peerid_type peer_id)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << std::hex << peer_id;
|
||||
return epee::string_tools::pad_string(s.str(), 16, '0', true);
|
||||
}
|
||||
using boost::uuids::uuid;
|
||||
using peerid_type = uint64_t;
|
||||
|
||||
#pragma pack (push, 1)
|
||||
|
||||
struct network_address_old
|
||||
{
|
||||
uint32_t ip;
|
||||
uint32_t port;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(ip)
|
||||
KV_SERIALIZE(port)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
template<typename AddressType>
|
||||
struct peerlist_entry_base
|
||||
struct peerlist_entry
|
||||
{
|
||||
AddressType adr;
|
||||
epee::net_utils::network_address adr;
|
||||
peerid_type id;
|
||||
int64_t last_seen;
|
||||
uint32_t pruning_seed;
|
||||
uint16_t rpc_port;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(adr)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE_OPT(last_seen, (int64_t)0)
|
||||
KV_SERIALIZE_OPT(pruning_seed, (uint32_t)0)
|
||||
KV_SERIALIZE_OPT(rpc_port, (uint16_t)0)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
typedef peerlist_entry_base<epee::net_utils::network_address> peerlist_entry;
|
||||
|
||||
template<typename AddressType>
|
||||
struct anchor_peerlist_entry_base
|
||||
struct anchor_peerlist_entry
|
||||
{
|
||||
AddressType adr;
|
||||
epee::net_utils::network_address adr;
|
||||
peerid_type id;
|
||||
int64_t first_seen;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(adr)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(first_seen)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
typedef anchor_peerlist_entry_base<epee::net_utils::network_address> anchor_peerlist_entry;
|
||||
|
||||
template<typename AddressType>
|
||||
struct connection_entry_base
|
||||
struct connection_entry
|
||||
{
|
||||
AddressType adr;
|
||||
epee::net_utils::network_address adr;
|
||||
peerid_type id;
|
||||
bool is_income;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(adr)
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(is_income)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
typedef connection_entry_base<epee::net_utils::network_address> connection_entry;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
inline
|
||||
std::string print_peerlist_to_string(const std::vector<peerlist_entry>& pl)
|
||||
{
|
||||
time_t now_time = 0;
|
||||
time(&now_time);
|
||||
std::stringstream ss;
|
||||
ss << std::setfill ('0') << std::setw (8) << std::hex << std::noshowbase;
|
||||
for(const peerlist_entry& pe: pl)
|
||||
{
|
||||
ss << peerid_to_string(pe.id) << "\t" << pe.adr.str()
|
||||
<< " \trpc port " << (pe.rpc_port > 0 ? std::to_string(pe.rpc_port) : "-")
|
||||
<< " \tpruning seed " << pe.pruning_seed
|
||||
<< " \tlast_seen: " << (pe.last_seen == 0 ? std::string("never") : epee::misc_utils::get_time_interval_string(now_time - pe.last_seen))
|
||||
<< std::endl;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string print_peerlist_to_string(const std::vector<peerlist_entry>& pl);
|
||||
|
||||
struct network_config
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(max_out_connection_count)
|
||||
KV_SERIALIZE(max_in_connection_count)
|
||||
KV_SERIALIZE(handshake_interval)
|
||||
KV_SERIALIZE(packet_max_size)
|
||||
KV_SERIALIZE(config_id)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
|
||||
uint32_t max_out_connection_count;
|
||||
uint32_t max_in_connection_count;
|
||||
uint32_t connection_timeout;
|
||||
|
@ -155,56 +84,44 @@ namespace nodetool
|
|||
uint32_t packet_max_size;
|
||||
uint32_t config_id;
|
||||
uint32_t send_peerlist_sz;
|
||||
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
struct basic_node_data
|
||||
{
|
||||
uuid network_id;
|
||||
uuid network_id;
|
||||
uint32_t my_port;
|
||||
uint16_t rpc_port;
|
||||
peerid_type peer_id;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB(network_id)
|
||||
KV_SERIALIZE(peer_id)
|
||||
KV_SERIALIZE(my_port)
|
||||
KV_SERIALIZE_OPT(rpc_port, (uint16_t)(0))
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define P2P_COMMANDS_POOL_BASE 1000
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
template<class Payload>
|
||||
struct COMMAND_HANDSHAKE_T
|
||||
{
|
||||
const static int ID = P2P_COMMANDS_POOL_BASE + 1;
|
||||
struct COMMAND_HANDSHAKE
|
||||
{
|
||||
const static int ID = P2P_COMMANDS_POOL_BASE + 1;
|
||||
|
||||
struct request
|
||||
{
|
||||
basic_node_data node_data;
|
||||
Payload payload_data;
|
||||
cryptonote::CORE_SYNC_DATA payload_data;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(node_data)
|
||||
KV_SERIALIZE(payload_data)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
basic_node_data node_data;
|
||||
Payload payload_data;
|
||||
cryptonote::CORE_SYNC_DATA payload_data;
|
||||
std::vector<peerlist_entry> local_peerlist_new;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(node_data)
|
||||
KV_SERIALIZE(payload_data)
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -212,29 +129,24 @@ namespace nodetool
|
|||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
template<class Payload>
|
||||
struct COMMAND_TIMED_SYNC_T
|
||||
struct COMMAND_TIMED_SYNC
|
||||
{
|
||||
const static int ID = P2P_COMMANDS_POOL_BASE + 2;
|
||||
|
||||
struct request
|
||||
{
|
||||
Payload payload_data;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(payload_data)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
cryptonote::CORE_SYNC_DATA payload_data;
|
||||
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
uint64_t local_time;
|
||||
Payload payload_data;
|
||||
cryptonote::CORE_SYNC_DATA payload_data;
|
||||
std::vector<peerlist_entry> local_peerlist_new;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(payload_data)
|
||||
KV_SERIALIZE(local_peerlist_new)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -245,20 +157,18 @@ namespace nodetool
|
|||
struct COMMAND_PING
|
||||
{
|
||||
/*
|
||||
Used to make "callback" connection, to be sure that opponent node
|
||||
Used to make "callback" connection, to be sure that opponent node
|
||||
have accessible connection point. Only other nodes can add peer to peerlist,
|
||||
and ONLY in case when peer has accepted connection and answered to ping.
|
||||
*/
|
||||
const static int ID = P2P_COMMANDS_POOL_BASE + 3;
|
||||
|
||||
#define PING_OK_RESPONSE_STATUS_TEXT "OK"
|
||||
static constexpr auto OK_RESPONSE = "OK"sv;
|
||||
|
||||
struct request
|
||||
{
|
||||
/*actually we don't need to send any real data*/
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
struct response
|
||||
|
@ -266,14 +176,11 @@ namespace nodetool
|
|||
std::string status;
|
||||
peerid_type peer_id;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
KV_SERIALIZE(peer_id)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
@ -284,17 +191,14 @@ namespace nodetool
|
|||
|
||||
struct request
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
uint32_t support_flags;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(support_flags)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
KV_MAP_SERIALIZABLE
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -205,8 +205,7 @@ namespace cryptonote::rpc {
|
|||
|
||||
const command_line::arg_descriptor<std::string> core_rpc_server::arg_bootstrap_daemon_address = {
|
||||
"bootstrap-daemon-address"
|
||||
, "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced.\n"
|
||||
"Use 'auto' to enable automatic public nodes discovering and bootstrap daemon switching"
|
||||
, "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced."
|
||||
, ""
|
||||
};
|
||||
|
||||
|
@ -1365,7 +1364,6 @@ namespace cryptonote::rpc {
|
|||
{"last_seen", peer.last_seen}
|
||||
};
|
||||
if (peer.pruning_seed) p["pruning_seed"] = peer.pruning_seed;
|
||||
if (peer.rpc_port) p["rpc_port"] = peer.rpc_port;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -1854,9 +1852,8 @@ namespace cryptonote::rpc {
|
|||
if (ci.localhost) info["localhost"] = true;
|
||||
if (ci.local_ip) info["local_ip"] = true;
|
||||
if (uint16_t port; tools::parse_int(ci.port, port) && port > 0) info["port"] = port;
|
||||
// Included for completeness, but undocumented as neither of these are currently actually used
|
||||
// or support on Oxen:
|
||||
if (ci.rpc_port > 0) info["rpc_port"] = ci.rpc_port;
|
||||
// Included for completeness, but undocumented as this is not currently actually used or
|
||||
// supported on Oxen:
|
||||
if (ci.pruning_seed) info["pruning_seed"] = ci.pruning_seed;
|
||||
return info;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue