2018-01-07 00:05:16 -05:00
|
|
|
// Copyright (c) 2014-2018, The Monero Project
|
2015-12-13 23:54:39 -05:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// All rights reserved.
|
2015-12-13 23:54:39 -05:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
2015-12-13 23:54:39 -05:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
2015-12-13 23:54:39 -05:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
2015-12-13 23:54:39 -05:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
2015-12-13 23:54:39 -05:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2015-12-13 23:54:39 -05:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
#pragma once
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 18:30:51 -04:00
|
|
|
#include <array>
|
2018-12-16 12:57:44 -05:00
|
|
|
#include <atomic>
|
|
|
|
#include <boost/asio/io_service.hpp>
|
|
|
|
#include <boost/asio/ip/tcp.hpp>
|
2014-03-03 17:07:58 -05:00
|
|
|
#include <boost/thread.hpp>
|
2018-12-16 12:57:44 -05:00
|
|
|
#include <boost/optional/optional_fwd.hpp>
|
2014-03-03 17:07:58 -05:00
|
|
|
#include <boost/program_options/options_description.hpp>
|
|
|
|
#include <boost/program_options/variables_map.hpp>
|
2014-09-08 13:40:28 -04:00
|
|
|
#include <boost/uuid/uuid.hpp>
|
2018-12-16 12:57:44 -05:00
|
|
|
#include <functional>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-03-03 17:07:58 -05:00
|
|
|
|
2014-09-04 22:14:36 -04:00
|
|
|
#include "cryptonote_config.h"
|
2014-03-03 17:07:58 -05:00
|
|
|
#include "warnings.h"
|
2018-11-15 11:29:34 -05:00
|
|
|
#include "net/abstract_tcp_server2.h"
|
|
|
|
#include "net/levin_protocol_handler.h"
|
|
|
|
#include "net/levin_protocol_handler_async.h"
|
2014-03-03 17:07:58 -05:00
|
|
|
#include "p2p_protocol_defs.h"
|
|
|
|
#include "storages/levin_abstract_invoke2.h"
|
|
|
|
#include "net_peerlist.h"
|
|
|
|
#include "math_helper.h"
|
|
|
|
#include "net_node_common.h"
|
2018-12-16 12:57:44 -05:00
|
|
|
#include "net/enums.h"
|
|
|
|
#include "net/fwd.h"
|
2014-05-25 13:06:40 -04:00
|
|
|
#include "common/command_line.h"
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
PUSH_WARNINGS
|
|
|
|
DISABLE_VS_WARNINGS(4355)
|
|
|
|
|
|
|
|
namespace nodetool
|
|
|
|
{
|
2018-12-16 12:57:44 -05:00
|
|
|
struct proxy
|
|
|
|
{
|
|
|
|
proxy()
|
|
|
|
: max_connections(-1),
|
|
|
|
address(),
|
|
|
|
zone(epee::net_utils::zone::invalid)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::int64_t max_connections;
|
|
|
|
boost::asio::ip::tcp::endpoint address;
|
|
|
|
epee::net_utils::zone zone;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct anonymous_inbound
|
|
|
|
{
|
|
|
|
anonymous_inbound()
|
|
|
|
: max_connections(-1),
|
|
|
|
local_ip(),
|
|
|
|
local_port(),
|
|
|
|
our_address(),
|
|
|
|
default_remote()
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::int64_t max_connections;
|
|
|
|
std::string local_ip;
|
|
|
|
std::string local_port;
|
|
|
|
epee::net_utils::network_address our_address;
|
|
|
|
epee::net_utils::network_address default_remote;
|
|
|
|
};
|
|
|
|
|
|
|
|
boost::optional<std::vector<proxy>> get_proxies(const boost::program_options::variables_map& vm);
|
|
|
|
boost::optional<std::vector<anonymous_inbound>> get_anonymous_inbounds(const boost::program_options::variables_map& vm);
|
|
|
|
|
|
|
|
//! \return True if `commnd` is filtered (ignored/dropped) for `address`
|
|
|
|
bool is_filtered_command(epee::net_utils::network_address const& address, int command);
|
|
|
|
|
|
|
|
// hides boost::future and chrono stuff from mondo template file
|
|
|
|
boost::optional<boost::asio::ip::tcp::socket>
|
|
|
|
socks_connect_internal(const std::atomic<bool>& stop_signal, boost::asio::io_service& service, const boost::asio::ip::tcp::endpoint& proxy, const epee::net_utils::network_address& remote);
|
|
|
|
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
template<class base_type>
|
|
|
|
struct p2p_connection_context_t: base_type //t_payload_net_handler::connection_context //public net_utils::connection_context_base
|
|
|
|
{
|
2017-08-08 12:23:02 -04:00
|
|
|
p2p_connection_context_t(): peer_id(0), support_flags(0), m_in_timedsync(false) {}
|
2017-07-29 06:17:43 -04:00
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
peerid_type peer_id;
|
2016-10-26 15:00:08 -04:00
|
|
|
uint32_t support_flags;
|
2017-07-29 06:17:43 -04:00
|
|
|
bool m_in_timedsync;
|
2014-03-03 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class t_payload_net_handler>
|
2014-05-25 13:06:40 -04:00
|
|
|
class node_server: public epee::levin::levin_commands_handler<p2p_connection_context_t<typename t_payload_net_handler::connection_context> >,
|
2015-11-23 12:34:55 -05:00
|
|
|
public i_p2p_endpoint<typename t_payload_net_handler::connection_context>,
|
|
|
|
public epee::net_utils::i_connection_filter
|
2014-03-03 17:07:58 -05:00
|
|
|
{
|
|
|
|
struct by_conn_id{};
|
|
|
|
struct by_peer_id{};
|
|
|
|
struct by_addr{};
|
|
|
|
|
|
|
|
typedef p2p_connection_context_t<typename t_payload_net_handler::connection_context> p2p_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;
|
|
|
|
|
2018-12-16 12:57:44 -05:00
|
|
|
typedef epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<p2p_connection_context>> net_server;
|
|
|
|
|
|
|
|
struct network_zone;
|
|
|
|
using connect_func = boost::optional<p2p_connection_context>(network_zone&, epee::net_utils::network_address const&);
|
|
|
|
|
|
|
|
struct config
|
|
|
|
{
|
|
|
|
config()
|
|
|
|
: m_net_config(),
|
|
|
|
m_peer_id(crypto::rand<uint64_t>()),
|
|
|
|
m_support_flags(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
network_config m_net_config;
|
|
|
|
uint64_t m_peer_id;
|
|
|
|
uint32_t m_support_flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct network_zone
|
|
|
|
{
|
|
|
|
network_zone()
|
|
|
|
: m_connect(nullptr),
|
|
|
|
m_net_server(epee::net_utils::e_connection_type_P2P),
|
|
|
|
m_bind_ip(),
|
|
|
|
m_port(),
|
|
|
|
m_our_address(),
|
|
|
|
m_peerlist(),
|
|
|
|
m_config{},
|
|
|
|
m_proxy_address(),
|
|
|
|
m_current_number_of_out_peers(0),
|
|
|
|
m_current_number_of_in_peers(0),
|
|
|
|
m_can_pingback(false)
|
|
|
|
{
|
|
|
|
set_config_defaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
network_zone(boost::asio::io_service& public_service)
|
|
|
|
: m_connect(nullptr),
|
|
|
|
m_net_server(public_service, epee::net_utils::e_connection_type_P2P),
|
|
|
|
m_bind_ip(),
|
|
|
|
m_port(),
|
|
|
|
m_our_address(),
|
|
|
|
m_peerlist(),
|
|
|
|
m_config{},
|
|
|
|
m_proxy_address(),
|
|
|
|
m_current_number_of_out_peers(0),
|
|
|
|
m_current_number_of_in_peers(0),
|
|
|
|
m_can_pingback(false)
|
|
|
|
{
|
|
|
|
set_config_defaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
connect_func* m_connect;
|
|
|
|
net_server m_net_server;
|
|
|
|
std::string m_bind_ip;
|
|
|
|
std::string m_port;
|
|
|
|
epee::net_utils::network_address m_our_address; // in anonymity networks
|
|
|
|
peerlist_manager m_peerlist;
|
|
|
|
config m_config;
|
|
|
|
boost::asio::ip::tcp::endpoint m_proxy_address;
|
|
|
|
std::atomic<unsigned int> m_current_number_of_out_peers;
|
|
|
|
std::atomic<unsigned int> m_current_number_of_in_peers;
|
|
|
|
bool m_can_pingback;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void set_config_defaults() noexcept
|
|
|
|
{
|
|
|
|
// at this moment we have a hardcoded config
|
|
|
|
m_config.m_net_config.handshake_interval = P2P_DEFAULT_HANDSHAKE_INTERVAL;
|
|
|
|
m_config.m_net_config.packet_max_size = P2P_DEFAULT_PACKET_MAX_SIZE;
|
|
|
|
m_config.m_net_config.config_id = 0;
|
|
|
|
m_config.m_net_config.connection_timeout = P2P_DEFAULT_CONNECTION_TIMEOUT;
|
|
|
|
m_config.m_net_config.ping_connection_timeout = P2P_DEFAULT_PING_CONNECTION_TIMEOUT;
|
|
|
|
m_config.m_net_config.send_peerlist_sz = P2P_DEFAULT_PEERS_IN_HANDSHAKE;
|
|
|
|
m_config.m_support_flags = 0; // only set in public zone
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
public:
|
|
|
|
typedef t_payload_net_handler payload_net_handler;
|
2014-09-08 13:40:28 -04:00
|
|
|
|
2015-04-01 13:00:45 -04:00
|
|
|
node_server(t_payload_net_handler& payload_handler)
|
2018-12-16 12:57:44 -05:00
|
|
|
: m_payload_handler(payload_handler),
|
|
|
|
m_external_port(0),
|
|
|
|
m_allow_local_ip(false),
|
|
|
|
m_hide_my_port(false),
|
|
|
|
m_no_igd(false),
|
|
|
|
m_offline(false),
|
|
|
|
m_save_graph(false),
|
|
|
|
is_closing(false),
|
|
|
|
m_network_id()
|
2015-04-20 13:17:11 -04:00
|
|
|
{}
|
2018-12-16 12:57:44 -05:00
|
|
|
virtual ~node_server();
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
static void init_options(boost::program_options::options_description& desc);
|
|
|
|
|
|
|
|
bool run();
|
2018-12-16 12:57:44 -05:00
|
|
|
network_zone& add_zone(epee::net_utils::zone zone);
|
2015-01-29 17:10:53 -05:00
|
|
|
bool init(const boost::program_options::variables_map& vm);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool deinit();
|
|
|
|
bool send_stop_signal();
|
2017-09-01 03:50:22 -04:00
|
|
|
uint32_t get_this_peer_port(){return m_listening_port;}
|
2014-03-03 17:07:58 -05:00
|
|
|
t_payload_net_handler& get_payload_object();
|
|
|
|
|
|
|
|
// debug functions
|
|
|
|
bool log_peerlist();
|
|
|
|
bool log_connections();
|
2018-12-16 12:57:44 -05:00
|
|
|
|
|
|
|
// These functions only return information for the "public" zone
|
|
|
|
virtual uint64_t get_public_connections_count();
|
|
|
|
size_t get_public_outgoing_connections_count();
|
|
|
|
size_t get_public_white_peers_count();
|
|
|
|
size_t get_public_gray_peers_count();
|
|
|
|
void get_public_peerlist(std::vector<peerlist_entry>& gray, std::vector<peerlist_entry>& white);
|
|
|
|
size_t get_zone_count() const { return m_network_zones.size(); }
|
|
|
|
|
|
|
|
void change_max_out_public_peers(size_t count);
|
|
|
|
void change_max_in_public_peers(size_t count);
|
2017-05-27 06:35:54 -04:00
|
|
|
virtual bool block_host(const epee::net_utils::network_address &adress, time_t seconds = P2P_IP_BLOCKTIME);
|
|
|
|
virtual bool unblock_host(const epee::net_utils::network_address &address);
|
|
|
|
virtual std::map<std::string, time_t> get_blocked_hosts() { CRITICAL_REGION_LOCAL(m_blocked_hosts_lock); return m_blocked_hosts; }
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 18:30:51 -04:00
|
|
|
|
|
|
|
virtual void add_used_stripe_peer(const typename t_payload_net_handler::connection_context &context);
|
|
|
|
virtual void remove_used_stripe_peer(const typename t_payload_net_handler::connection_context &context);
|
|
|
|
virtual void clear_used_stripe_peers();
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
private:
|
2014-09-17 15:35:52 -04:00
|
|
|
const std::vector<std::string> m_seed_nodes_list =
|
|
|
|
{ "seeds.moneroseeds.se"
|
|
|
|
, "seeds.moneroseeds.ae.org"
|
|
|
|
, "seeds.moneroseeds.ch"
|
|
|
|
, "seeds.moneroseeds.li"
|
|
|
|
};
|
2015-12-13 23:54:39 -05:00
|
|
|
|
2015-01-05 14:30:17 -05:00
|
|
|
bool islimitup=false;
|
|
|
|
bool islimitdown=false;
|
2014-09-17 15:35:52 -04:00
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
typedef COMMAND_REQUEST_STAT_INFO_T<typename t_payload_net_handler::stat_info> COMMAND_REQUEST_STAT_INFO;
|
|
|
|
|
|
|
|
CHAIN_LEVIN_INVOKE_MAP2(p2p_connection_context); //move levin_commands_handler interface invoke(...) callbacks into invoke map
|
|
|
|
CHAIN_LEVIN_NOTIFY_MAP2(p2p_connection_context); //move levin_commands_handler interface notify(...) callbacks into nothing
|
|
|
|
|
|
|
|
BEGIN_INVOKE_MAP2(node_server)
|
2018-12-16 12:57:44 -05:00
|
|
|
if (is_filtered_command(context.m_remote_address, command))
|
|
|
|
return LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED;
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
HANDLE_INVOKE_T2(COMMAND_HANDSHAKE, &node_server::handle_handshake)
|
|
|
|
HANDLE_INVOKE_T2(COMMAND_TIMED_SYNC, &node_server::handle_timed_sync)
|
|
|
|
HANDLE_INVOKE_T2(COMMAND_PING, &node_server::handle_ping)
|
|
|
|
#ifdef ALLOW_DEBUG_COMMANDS
|
|
|
|
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)
|
|
|
|
#endif
|
2016-10-26 15:00:08 -04:00
|
|
|
HANDLE_INVOKE_T2(COMMAND_REQUEST_SUPPORT_FLAGS, &node_server::handle_get_support_flags)
|
2014-03-03 17:07:58 -05:00
|
|
|
CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT(m_payload_handler, typename t_payload_net_handler::connection_context&)
|
|
|
|
END_INVOKE_MAP2()
|
|
|
|
|
2017-02-08 19:11:58 -05:00
|
|
|
enum PeerType { anchor = 0, white, gray };
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
//----------------- commands handlers ----------------------------------------------
|
|
|
|
int handle_handshake(int command, typename COMMAND_HANDSHAKE::request& arg, typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context);
|
|
|
|
int handle_timed_sync(int command, typename COMMAND_TIMED_SYNC::request& arg, typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context);
|
|
|
|
int handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, p2p_connection_context& context);
|
|
|
|
#ifdef ALLOW_DEBUG_COMMANDS
|
|
|
|
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);
|
|
|
|
#endif
|
2016-10-26 15:00:08 -04:00
|
|
|
int handle_get_support_flags(int command, COMMAND_REQUEST_SUPPORT_FLAGS::request& arg, COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool init_config();
|
2017-01-22 06:37:55 -05:00
|
|
|
bool make_default_peer_id();
|
2014-03-03 17:07:58 -05:00
|
|
|
bool make_default_config();
|
|
|
|
bool store_config();
|
2018-12-16 12:57:44 -05:00
|
|
|
bool check_trust(const proof_of_trust& tr, epee::net_utils::zone zone_type);
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
//----------------- levin_commands_handler -------------------------------------------------------------
|
|
|
|
virtual void on_connection_new(p2p_connection_context& context);
|
|
|
|
virtual void on_connection_close(p2p_connection_context& context);
|
|
|
|
virtual void callback(p2p_connection_context& context);
|
|
|
|
//----------------- i_p2p_endpoint -------------------------------------------------------------
|
2018-12-16 12:57:44 -05:00
|
|
|
virtual bool relay_notify_to_list(int command, const epee::span<const uint8_t> data_buff, std::vector<std::pair<epee::net_utils::zone, boost::uuids::uuid>> connections);
|
2018-12-06 13:04:33 -05:00
|
|
|
virtual bool invoke_command_to_peer(int command, const epee::span<const uint8_t> req_buff, std::string& resp_buff, const epee::net_utils::connection_context_base& context);
|
|
|
|
virtual bool invoke_notify_to_peer(int command, const epee::span<const uint8_t> req_buff, const epee::net_utils::connection_context_base& context);
|
2014-03-03 17:07:58 -05:00
|
|
|
virtual bool drop_connection(const epee::net_utils::connection_context_base& context);
|
|
|
|
virtual void request_callback(const epee::net_utils::connection_context_base& context);
|
2016-10-26 15:00:08 -04:00
|
|
|
virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
|
2017-07-02 17:41:15 -04:00
|
|
|
virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
|
2017-05-27 06:35:54 -04:00
|
|
|
virtual bool add_host_fail(const epee::net_utils::network_address &address);
|
2015-11-23 12:34:55 -05:00
|
|
|
//----------------- i_connection_filter --------------------------------------------------------
|
2017-05-27 06:35:54 -04:00
|
|
|
virtual bool is_remote_host_allowed(const epee::net_utils::network_address &address);
|
2014-03-03 17:07:58 -05:00
|
|
|
//-----------------------------------------------------------------------------------------------
|
2017-05-27 06:35:54 -04:00
|
|
|
bool parse_peer_from_string(epee::net_utils::network_address& pe, const std::string& node_addr, uint16_t default_port = 0);
|
2014-09-08 12:51:04 -04:00
|
|
|
bool handle_command_line(
|
|
|
|
const boost::program_options::variables_map& vm
|
|
|
|
);
|
2014-03-03 17:07:58 -05:00
|
|
|
bool idle_worker();
|
2018-12-05 17:25:27 -05:00
|
|
|
bool handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context);
|
2018-12-16 12:57:44 -05:00
|
|
|
bool get_local_node_data(basic_node_data& node_data, const network_zone& zone);
|
2014-03-03 17:07:58 -05:00
|
|
|
//bool get_local_handshake_data(handshake_data& hshd);
|
|
|
|
|
2018-12-05 17:25:27 -05:00
|
|
|
bool merge_peerlist_with_local(const std::vector<peerlist_entry>& bs);
|
|
|
|
bool fix_time_delta(std::vector<peerlist_entry>& local_peerlist, time_t local_time, int64_t& delta);
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
bool connections_maker();
|
|
|
|
bool peer_sync_idle_maker();
|
|
|
|
bool do_handshake_with_peer(peerid_type& pi, p2p_connection_context& context, bool just_take_peerlist = false);
|
2014-05-25 13:06:40 -04:00
|
|
|
bool do_peer_timed_sync(const epee::net_utils::connection_context_base& context, peerid_type peer_id);
|
2014-03-03 17:07:58 -05:00
|
|
|
|
2017-02-08 19:11:58 -05:00
|
|
|
bool make_new_connection_from_anchor_peerlist(const std::vector<anchor_peerlist_entry>& anchor_peerlist);
|
2018-12-16 12:57:44 -05:00
|
|
|
bool make_new_connection_from_peerlist(network_zone& zone, bool use_white_list);
|
2017-05-27 06:35:54 -04:00
|
|
|
bool try_to_connect_and_handshake_with_new_peer(const epee::net_utils::network_address& na, bool just_take_peerlist = false, uint64_t last_seen_stamp = 0, PeerType peer_type = white, uint64_t first_seen_stamp = 0);
|
2014-03-03 17:07:58 -05:00
|
|
|
size_t get_random_index_with_fixed_probability(size_t max_index);
|
|
|
|
bool is_peer_used(const peerlist_entry& peer);
|
2017-02-08 19:11:58 -05:00
|
|
|
bool is_peer_used(const anchor_peerlist_entry& peer);
|
2017-05-27 06:35:54 -04:00
|
|
|
bool is_addr_connected(const epee::net_utils::network_address& peer);
|
2017-08-29 17:28:23 -04:00
|
|
|
void add_upnp_port_mapping(uint32_t port);
|
|
|
|
void delete_upnp_port_mapping(uint32_t port);
|
2014-03-03 17:07:58 -05:00
|
|
|
template<class t_callback>
|
2018-02-02 13:45:12 -05:00
|
|
|
bool try_ping(basic_node_data& node_data, p2p_connection_context& context, const t_callback &cb);
|
2016-10-26 15:00:08 -04:00
|
|
|
bool try_get_support_flags(const p2p_connection_context& context, std::function<void(p2p_connection_context&, const uint32_t&)> f);
|
2018-12-16 12:57:44 -05:00
|
|
|
bool make_expected_connections_count(network_zone& zone, PeerType peer_type, size_t expected_connections);
|
2017-05-27 06:35:54 -04:00
|
|
|
void cache_connect_fail_info(const epee::net_utils::network_address& addr);
|
|
|
|
bool is_addr_recently_failed(const epee::net_utils::network_address& addr);
|
|
|
|
bool is_priority_node(const epee::net_utils::network_address& na);
|
2018-02-16 06:04:04 -05:00
|
|
|
std::set<std::string> get_seed_nodes(cryptonote::network_type nettype) const;
|
2017-08-09 17:44:39 -04:00
|
|
|
bool connect_to_seed();
|
2014-05-25 13:06:40 -04:00
|
|
|
|
|
|
|
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);
|
2014-03-03 17:07:58 -05:00
|
|
|
|
2018-12-16 12:57:44 -05:00
|
|
|
bool set_max_out_peers(network_zone& zone, int64_t max);
|
|
|
|
bool set_max_in_peers(network_zone& zone, int64_t max);
|
2015-12-13 23:54:39 -05:00
|
|
|
bool set_tos_flag(const boost::program_options::variables_map& vm, int limit);
|
|
|
|
|
|
|
|
bool set_rate_up_limit(const boost::program_options::variables_map& vm, int64_t limit);
|
|
|
|
bool set_rate_down_limit(const boost::program_options::variables_map& vm, int64_t limit);
|
|
|
|
bool set_rate_limit(const boost::program_options::variables_map& vm, int64_t limit);
|
2015-01-05 14:30:17 -05:00
|
|
|
|
2017-05-27 06:35:54 -04:00
|
|
|
bool has_too_many_connections(const epee::net_utils::network_address &address);
|
2018-12-16 12:57:44 -05:00
|
|
|
uint64_t get_connections_count();
|
|
|
|
size_t get_incoming_connections_count();
|
|
|
|
size_t get_incoming_connections_count(network_zone&);
|
|
|
|
size_t get_outgoing_connections_count();
|
|
|
|
size_t get_outgoing_connections_count(network_zone&);
|
2017-01-14 07:21:20 -05:00
|
|
|
|
2017-05-27 06:35:54 -04:00
|
|
|
bool check_connection_and_handshake_with_peer(const epee::net_utils::network_address& na, uint64_t last_seen_stamp);
|
2017-01-20 18:59:04 -05:00
|
|
|
bool gray_peerlist_housekeeping();
|
2018-05-25 07:34:52 -04:00
|
|
|
bool check_incoming_connections();
|
2017-01-20 18:59:04 -05:00
|
|
|
|
2015-02-24 15:02:48 -05:00
|
|
|
void kill() { ///< will be called e.g. from deinit()
|
2015-12-13 23:54:39 -05:00
|
|
|
_info("Killing the net_node");
|
|
|
|
is_closing = true;
|
|
|
|
if(mPeersLoggerThread != nullptr)
|
|
|
|
mPeersLoggerThread->join(); // make sure the thread finishes
|
|
|
|
_info("Joined extra background net_node threads");
|
|
|
|
}
|
2015-02-24 15:02:48 -05:00
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
//debug functions
|
|
|
|
std::string print_connections_container();
|
|
|
|
|
|
|
|
|
2015-12-13 23:54:39 -05:00
|
|
|
public:
|
2015-04-01 13:00:45 -04:00
|
|
|
|
2015-12-13 23:54:39 -05:00
|
|
|
void set_save_graph(bool save_graph)
|
|
|
|
{
|
|
|
|
m_save_graph = save_graph;
|
|
|
|
epee::net_utils::connection_basic::set_save_graph(save_graph);
|
|
|
|
}
|
|
|
|
private:
|
2014-03-03 17:07:58 -05:00
|
|
|
std::string m_config_folder;
|
|
|
|
|
|
|
|
bool m_have_address;
|
|
|
|
bool m_first_connection_maker_call;
|
2017-09-01 03:50:22 -04:00
|
|
|
uint32_t m_listening_port;
|
2014-03-03 17:07:58 -05:00
|
|
|
uint32_t m_external_port;
|
|
|
|
bool m_allow_local_ip;
|
|
|
|
bool m_hide_my_port;
|
2015-01-05 14:30:17 -05:00
|
|
|
bool m_no_igd;
|
2015-12-07 15:21:45 -05:00
|
|
|
bool m_offline;
|
2015-02-12 14:59:39 -05:00
|
|
|
std::atomic<bool> m_save_graph;
|
2015-02-24 15:02:48 -05:00
|
|
|
std::atomic<bool> is_closing;
|
2016-02-18 16:30:10 -05:00
|
|
|
std::unique_ptr<boost::thread> mPeersLoggerThread;
|
2014-03-03 17:07:58 -05:00
|
|
|
//critical_section m_connections_lock;
|
|
|
|
//connections_indexed_container m_connections;
|
|
|
|
|
|
|
|
t_payload_net_handler& m_payload_handler;
|
2018-12-16 12:57:44 -05:00
|
|
|
peerlist_storage m_peerlist_storage;
|
2014-03-03 17:07:58 -05:00
|
|
|
|
2014-05-25 13:06:40 -04:00
|
|
|
epee::math_helper::once_a_time_seconds<P2P_DEFAULT_HANDSHAKE_INTERVAL> m_peer_handshake_idle_maker_interval;
|
|
|
|
epee::math_helper::once_a_time_seconds<1> m_connections_maker_interval;
|
|
|
|
epee::math_helper::once_a_time_seconds<60*30, false> m_peerlist_store_interval;
|
2017-01-20 18:59:04 -05:00
|
|
|
epee::math_helper::once_a_time_seconds<60> m_gray_peerlist_housekeeping_interval;
|
2018-11-01 18:00:01 -04:00
|
|
|
epee::math_helper::once_a_time_seconds<3600, false> m_incoming_connections_interval;
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
#ifdef ALLOW_DEBUG_COMMANDS
|
|
|
|
uint64_t m_last_stat_request_time;
|
|
|
|
#endif
|
2017-05-27 06:35:54 -04:00
|
|
|
std::list<epee::net_utils::network_address> m_priority_peers;
|
|
|
|
std::vector<epee::net_utils::network_address> m_exclusive_peers;
|
|
|
|
std::vector<epee::net_utils::network_address> m_seed_nodes;
|
2018-04-29 09:57:08 -04:00
|
|
|
bool m_fallback_seed_nodes_added;
|
2018-12-16 12:57:44 -05:00
|
|
|
std::vector<nodetool::peerlist_entry> m_command_line_peers;
|
2014-03-03 17:07:58 -05:00
|
|
|
uint64_t m_peer_livetime;
|
|
|
|
//keep connections to initiate some interactions
|
2018-12-16 12:57:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
static boost::optional<p2p_connection_context> public_connect(network_zone&, epee::net_utils::network_address const&);
|
|
|
|
static boost::optional<p2p_connection_context> socks_connect(network_zone&, epee::net_utils::network_address const&);
|
|
|
|
|
|
|
|
|
|
|
|
/* A `std::map` provides constant iterators and key/value pointers even with
|
|
|
|
inserts/erases to _other_ elements. This makes the configuration step easier
|
|
|
|
since references can safely be stored on the stack. Do not insert/erase
|
|
|
|
after configuration and before destruction, lock safety would need to be
|
|
|
|
added. `std::map::operator[]` WILL insert! */
|
|
|
|
std::map<epee::net_utils::zone, network_zone> m_network_zones;
|
|
|
|
|
2015-11-23 12:34:55 -05:00
|
|
|
|
2017-05-27 06:35:54 -04:00
|
|
|
std::map<epee::net_utils::network_address, time_t> m_conn_fails_cache;
|
2015-11-23 12:34:55 -05:00
|
|
|
epee::critical_section m_conn_fails_cache_lock;
|
|
|
|
|
2017-05-27 06:35:54 -04:00
|
|
|
epee::critical_section m_blocked_hosts_lock;
|
|
|
|
std::map<std::string, time_t> m_blocked_hosts;
|
2015-11-23 12:34:55 -05:00
|
|
|
|
2017-05-27 06:35:54 -04:00
|
|
|
epee::critical_section m_host_fails_score_lock;
|
|
|
|
std::map<std::string, uint64_t> m_host_fails_score;
|
2017-03-17 19:39:47 -04:00
|
|
|
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 18:30:51 -04:00
|
|
|
boost::mutex m_used_stripe_peers_mutex;
|
|
|
|
std::array<std::list<epee::net_utils::network_address>, 1 << CRYPTONOTE_PRUNING_LOG_STRIPES> m_used_stripe_peers;
|
|
|
|
|
2018-12-16 12:57:44 -05:00
|
|
|
boost::uuids::uuid m_network_id;
|
2018-02-16 06:04:04 -05:00
|
|
|
cryptonote::network_type m_nettype;
|
2014-03-03 17:07:58 -05:00
|
|
|
};
|
|
|
|
|
2018-10-31 17:47:20 -04:00
|
|
|
const int64_t default_limit_up = P2P_DEFAULT_LIMIT_RATE_UP; // kB/s
|
|
|
|
const int64_t default_limit_down = P2P_DEFAULT_LIMIT_RATE_DOWN; // kB/s
|
2017-11-29 17:53:58 -05:00
|
|
|
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_ip;
|
2018-02-16 06:04:04 -05:00
|
|
|
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_port;
|
2017-11-29 17:53:58 -05:00
|
|
|
extern const command_line::arg_descriptor<uint32_t> arg_p2p_external_port;
|
|
|
|
extern const command_line::arg_descriptor<bool> arg_p2p_allow_local_ip;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_peer;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_priority_node;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_exclusive_node;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_seed_node;
|
2018-12-16 12:57:44 -05:00
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_proxy;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_anonymous_inbound;
|
2017-11-29 17:53:58 -05:00
|
|
|
extern const command_line::arg_descriptor<bool> arg_p2p_hide_my_port;
|
|
|
|
|
|
|
|
extern const command_line::arg_descriptor<bool> arg_no_igd;
|
|
|
|
extern const command_line::arg_descriptor<bool> arg_offline;
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_out_peers;
|
2018-01-20 16:44:23 -05:00
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_in_peers;
|
2017-11-29 17:53:58 -05:00
|
|
|
extern const command_line::arg_descriptor<int> arg_tos_flag;
|
|
|
|
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_limit_rate_up;
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_limit_rate_down;
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_limit_rate;
|
|
|
|
|
|
|
|
extern const command_line::arg_descriptor<bool> arg_save_graph;
|
|
|
|
}
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
POP_WARNINGS
|
2018-12-16 12:57:44 -05:00
|
|
|
|