forked from lthn/blockchain
p2p: COMMAND_REQUEST_ANONYMIZED_PEERS (WIP)
This commit is contained in:
parent
f087117a33
commit
7606c69961
4 changed files with 30 additions and 224 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2014-2024 Zano Project
|
||||
// Copyright (c) 2014-2025 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
|
|
@ -57,8 +57,6 @@ namespace
|
|||
const command_line::arg_descriptor<std::string> arg_generate_genesis ("generate-genesis", "Generate genesis coinbase based on config file");
|
||||
const command_line::arg_descriptor<uint64_t> arg_genesis_split_amount ( "genesis-split-amount", "Set split amount for generating genesis block");
|
||||
const command_line::arg_descriptor<std::string> arg_get_info_flags ( "getinfo-flags-hex", "Set of bits for rpc-get-daemon-info", "");
|
||||
const command_line::arg_descriptor<int64_t> arg_set_peer_log_level ( "set-peer-log-level", "Set log level for remote peer");
|
||||
const command_line::arg_descriptor<std::string> arg_download_peer_log ( "download-peer-log", "Download log from remote peer <starting_offset>[,<count>]");
|
||||
const command_line::arg_descriptor<bool> arg_do_consloe_log ( "do-console-log", "Tool generates debug console output(debug purposes)");
|
||||
const command_line::arg_descriptor<std::string> arg_generate_integrated_address ( "generate-integrated-address", "Tool create integrated address from simple address and payment_id");
|
||||
const command_line::arg_descriptor<std::string> arg_pack_file ("pack-file", "perform gzip-packing and calculate hash for a given file");
|
||||
|
|
@ -923,152 +921,6 @@ bool invoke_debug_command(po::variables_map& vm, const crypto::secret_key& sk, n
|
|||
return net_utils::invoke_remote_command2(command_t::ID, req, rsp, transport);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
bool handle_set_peer_log_level(po::variables_map& vm)
|
||||
{
|
||||
crypto::secret_key sk = AUTO_VAL_INIT(sk);
|
||||
if (!get_private_key(sk, vm))
|
||||
{
|
||||
std::cout << "ERROR: secret key error" << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t log_level = command_line::get_arg(vm, arg_set_peer_log_level);
|
||||
if (log_level < LOG_LEVEL_0 || log_level > LOG_LEVEL_MAX)
|
||||
{
|
||||
std::cout << "Error: invalid log level value: " << log_level << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
net_utils::levin_client2 transport;
|
||||
peerid_type peer_id = 0;
|
||||
|
||||
COMMAND_SET_LOG_LEVEL::request req = AUTO_VAL_INIT(req);
|
||||
req.new_log_level = log_level;
|
||||
|
||||
COMMAND_SET_LOG_LEVEL::response rsp = AUTO_VAL_INIT(rsp);
|
||||
if (!invoke_debug_command<COMMAND_SET_LOG_LEVEL>(vm, sk, transport, peer_id, req, rsp))
|
||||
{
|
||||
std::cout << "ERROR: invoking COMMAND_SET_LOG_LEVEL failed" << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "OK! Log level changed: " << rsp.old_log_level << " -> " << rsp.current_log_level << ENDL;
|
||||
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
bool handle_download_peer_log(po::variables_map& vm)
|
||||
{
|
||||
crypto::secret_key sk = AUTO_VAL_INIT(sk);
|
||||
if (!get_private_key(sk, vm))
|
||||
{
|
||||
std::cout << "ERROR: secret key error" << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
int64_t start_offset_signed = 0;
|
||||
int64_t count = -1;
|
||||
|
||||
std::string arg_str = command_line::get_arg(vm, arg_download_peer_log);
|
||||
size_t comma_pos = arg_str.find(',');
|
||||
if (comma_pos != std::string::npos)
|
||||
{
|
||||
// count is specified
|
||||
if (!epee::string_tools::string_to_num_fast(arg_str.substr(comma_pos + 1), count) || count < 0)
|
||||
{
|
||||
std::cout << "ERROR: invalid argument: " << arg_str << ENDL;
|
||||
return false;
|
||||
}
|
||||
arg_str.erase(comma_pos);
|
||||
}
|
||||
if (!epee::string_tools::string_to_num_fast(arg_str, start_offset_signed) || start_offset_signed < 0)
|
||||
{
|
||||
std::cout << "ERROR: couldn't parse start_offset: " << arg_str << ENDL;
|
||||
return false;
|
||||
}
|
||||
uint64_t start_offset = static_cast<uint64_t>(start_offset_signed);
|
||||
|
||||
net_utils::levin_client2 transport;
|
||||
peerid_type peer_id = 0;
|
||||
|
||||
COMMAND_REQUEST_LOG::request req = AUTO_VAL_INIT(req);
|
||||
COMMAND_REQUEST_LOG::response rsp = AUTO_VAL_INIT(rsp);
|
||||
if (!invoke_debug_command<COMMAND_REQUEST_LOG>(vm, sk, transport, peer_id, req, rsp) || !rsp.error.empty())
|
||||
{
|
||||
std::cout << "ERROR: invoking COMMAND_REQUEST_LOG failed: " << rsp.error << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Current log level: " << rsp.current_log_level << ENDL;
|
||||
std::cout << "Current log size: " << rsp.current_log_size << ENDL;
|
||||
|
||||
if (start_offset == 0 && count == 0)
|
||||
return true; // a caller wanted to just get the info, end of story
|
||||
|
||||
if (start_offset >= rsp.current_log_size)
|
||||
{
|
||||
std::cout << "ERROR: invalid start offset: " << start_offset << ", log size: " << rsp.current_log_size << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Downloading..." << ENDL;
|
||||
|
||||
std::string local_filename = tools::get_default_data_dir() + "/log_" + epee::string_tools::num_to_string_fast(peer_id) + ".log";
|
||||
std::ofstream log{ local_filename, std::ifstream::binary };
|
||||
if (!log)
|
||||
{
|
||||
std::cout << "Couldn't open " << local_filename << " for writing." << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint64_t chunk_size = 1024 * 1024 * 5;
|
||||
uint64_t end_offset = start_offset;
|
||||
while (true)
|
||||
{
|
||||
req.log_chunk_offset = end_offset;
|
||||
req.log_chunk_size = std::min(chunk_size, rsp.current_log_size - req.log_chunk_offset);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
uint64_t bytes_left = count + start_offset - end_offset;
|
||||
req.log_chunk_size = std::min(req.log_chunk_size, bytes_left);
|
||||
}
|
||||
|
||||
if (req.log_chunk_size == 0)
|
||||
break;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
||||
if (!invoke_debug_command<COMMAND_REQUEST_LOG>(vm, sk, transport, peer_id, req, rsp) || !rsp.error.empty())
|
||||
{
|
||||
std::cout << "ERROR: invoking COMMAND_REQUEST_LOG failed: " << rsp.error << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!epee::zlib_helper::unpack(rsp.log_chunk))
|
||||
{
|
||||
std::cout << "ERROR: zip unpack failed" << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rsp.log_chunk.size() != req.log_chunk_size)
|
||||
{
|
||||
std::cout << "ERROR: unpacked size: " << rsp.log_chunk.size() << ", requested: " << req.log_chunk_size << ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
log.write(rsp.log_chunk.c_str(), rsp.log_chunk.size());
|
||||
|
||||
end_offset += req.log_chunk_size;
|
||||
|
||||
std::cout << end_offset - start_offset << " bytes downloaded" << ENDL;
|
||||
}
|
||||
|
||||
std::cout << "Remote log from offset " << start_offset << " to offset " << end_offset << " (" << end_offset - start_offset << " bytes) " <<
|
||||
"was successfully downloaded to " << local_filename << ENDL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool handle_generate_integrated_address(po::variables_map& vm)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2014-2019 Zano Project
|
||||
// Copyright (c) 2014-2025 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
|
|
@ -142,8 +142,7 @@ namespace nodetool
|
|||
HANDLE_INVOKE_T2(COMMAND_REQUEST_STAT_INFO, &node_server::handle_get_stat_info)
|
||||
HANDLE_INVOKE_T2(COMMAND_REQUEST_NETWORK_STATE, &node_server::handle_get_network_state)
|
||||
HANDLE_INVOKE_T2(COMMAND_REQUEST_PEER_ID, &node_server::handle_get_peer_id)
|
||||
HANDLE_INVOKE_T2(COMMAND_REQUEST_LOG, &node_server::handle_request_log)
|
||||
HANDLE_INVOKE_T2(COMMAND_SET_LOG_LEVEL, &node_server::handle_set_log_level)
|
||||
HANDLE_INVOKE_T2(COMMAND_REQUEST_ANONYMIZED_PEERS, &node_server::handle_request_anonymized_peers)
|
||||
}
|
||||
#endif
|
||||
CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT(m_payload_handler, typename t_payload_net_handler::connection_context&)
|
||||
|
|
@ -158,8 +157,7 @@ namespace nodetool
|
|||
int handle_get_stat_info(int command, typename COMMAND_REQUEST_STAT_INFO::request& arg, typename COMMAND_REQUEST_STAT_INFO::response& rsp, p2p_connection_context& context);
|
||||
int handle_get_network_state(int command, COMMAND_REQUEST_NETWORK_STATE::request& arg, COMMAND_REQUEST_NETWORK_STATE::response& rsp, p2p_connection_context& context);
|
||||
int handle_get_peer_id(int command, COMMAND_REQUEST_PEER_ID::request& arg, COMMAND_REQUEST_PEER_ID::response& rsp, p2p_connection_context& context);
|
||||
int handle_request_log(int command, COMMAND_REQUEST_LOG::request& arg, COMMAND_REQUEST_LOG::response& rsp, p2p_connection_context& context);
|
||||
int handle_set_log_level(int command, COMMAND_SET_LOG_LEVEL::request& arg, COMMAND_SET_LOG_LEVEL::response& rsp, p2p_connection_context& context);
|
||||
int handle_request_anonymized_peers(int command, COMMAND_REQUEST_ANONYMIZED_PEERS::request& req, COMMAND_REQUEST_ANONYMIZED_PEERS::response& rsp, p2p_connection_context& context);
|
||||
private:
|
||||
#endif
|
||||
bool init_config();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2014-2019 Zano Project
|
||||
// Copyright (c) 2014-2025 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
|
|
@ -1196,7 +1196,7 @@ namespace nodetool
|
|||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
int node_server<t_payload_net_handler>::handle_request_log(int command, COMMAND_REQUEST_LOG::request& req, COMMAND_REQUEST_LOG::response& rsp, p2p_connection_context& context)
|
||||
int node_server<t_payload_net_handler>::handle_request_anonymized_peers(int command, COMMAND_REQUEST_ANONYMIZED_PEERS::request& req, COMMAND_REQUEST_ANONYMIZED_PEERS::response& rsp, p2p_connection_context& context)
|
||||
{
|
||||
if (!check_trust(req.tr))
|
||||
{
|
||||
|
|
@ -1204,30 +1204,15 @@ namespace nodetool
|
|||
return 1;
|
||||
}
|
||||
|
||||
rsp.current_log_level = static_cast<int64_t>(log_space::get_set_log_detalisation_level());
|
||||
tools::get_log_chunk_gzipped(req.log_chunk_offset, req.log_chunk_size, rsp.log_chunk, rsp.error);
|
||||
rsp.current_log_size = tools::get_log_file_size();
|
||||
m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cn_context)
|
||||
{
|
||||
auto& el = rsp.peers.emplace_back();
|
||||
el.inbound = cn_context.m_is_income;
|
||||
el.time_started = cn_context.m_started;
|
||||
return true;
|
||||
});
|
||||
|
||||
return 1;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
int node_server<t_payload_net_handler>::handle_set_log_level(int command, COMMAND_SET_LOG_LEVEL::request& req, COMMAND_SET_LOG_LEVEL::response& rsp, p2p_connection_context& context)
|
||||
{
|
||||
if (!check_trust(req.tr))
|
||||
{
|
||||
drop_connection(context);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rsp.old_log_level = static_cast<int64_t>(log_space::get_set_log_detalisation_level());
|
||||
log_space::get_set_log_detalisation_level(true, static_cast<int>(req.new_log_level));
|
||||
rsp.current_log_level = static_cast<int64_t>(log_space::get_set_log_detalisation_level());
|
||||
|
||||
if (rsp.old_log_level != rsp.current_log_level)
|
||||
{
|
||||
LOG_PRINT_CC(context, "log level changed by debug command: " << rsp.old_log_level << " -> " << rsp.current_log_level, LOG_LEVEL_0);
|
||||
}
|
||||
std::shuffle(rsp.peers.begin(), rsp.peers.end(), crypto::uniform_random_bit_generator());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2025 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
|
|
@ -402,65 +402,36 @@ namespace nodetool
|
|||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
struct COMMAND_REQUEST_LOG
|
||||
struct COMMAND_REQUEST_ANONYMIZED_PEERS
|
||||
{
|
||||
const static int ID = P2P_COMMANDS_POOL_BASE + 7;
|
||||
const static int ID = P2P_COMMANDS_POOL_BASE + 100;
|
||||
|
||||
struct request
|
||||
{
|
||||
proof_of_trust tr;
|
||||
uint64_t log_chunk_offset;
|
||||
uint64_t log_chunk_size;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(tr)
|
||||
KV_SERIALIZE(log_chunk_offset)
|
||||
KV_SERIALIZE(log_chunk_size)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct anonymized_peer_info
|
||||
{
|
||||
uint64_t time_started;
|
||||
bool inbound;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(time_started)
|
||||
KV_SERIALIZE(inbound)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
int64_t current_log_level;
|
||||
uint64_t current_log_size;
|
||||
std::string error;
|
||||
std::string log_chunk;
|
||||
std::vector<anonymized_peer_info> peers;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(current_log_level)
|
||||
KV_SERIALIZE(current_log_size)
|
||||
KV_SERIALIZE(error)
|
||||
KV_SERIALIZE(log_chunk)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
struct COMMAND_SET_LOG_LEVEL
|
||||
{
|
||||
const static int ID = P2P_COMMANDS_POOL_BASE + 8;
|
||||
|
||||
struct request
|
||||
{
|
||||
proof_of_trust tr;
|
||||
int64_t new_log_level;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(tr)
|
||||
KV_SERIALIZE(new_log_level)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
int64_t old_log_level;
|
||||
int64_t current_log_level;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(old_log_level)
|
||||
KV_SERIALIZE(current_log_level)
|
||||
KV_SERIALIZE(peers)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue