aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/net_node.h22
-rw-r--r--src/p2p/net_node.inl136
-rw-r--r--src/p2p/p2p_networks.h36
3 files changed, 96 insertions, 98 deletions
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index d7576d5dd..759b21fcf 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -41,13 +41,14 @@
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/serialization/version.hpp>
+#include <boost/uuid/uuid.hpp>
+#include "cryptonote_config.h"
#include "warnings.h"
#include "net/levin_server_cp2.h"
#include "p2p_protocol_defs.h"
#include "storages/levin_abstract_invoke2.h"
#include "net_peerlist.h"
-#include "p2p_networks.h"
#include "math_helper.h"
#include "net_node_common.h"
#include "common/command_line.h"
@@ -78,14 +79,21 @@ namespace nodetool
public:
typedef t_payload_net_handler payload_net_handler;
- // Some code
- node_server(t_payload_net_handler& payload_handler):m_payload_handler(payload_handler), m_allow_local_ip(false), m_hide_my_port(false)
+
+ node_server(
+ t_payload_net_handler& payload_handler
+ , boost::uuids::uuid network_id
+ )
+ : m_payload_handler(payload_handler)
+ , m_allow_local_ip(false)
+ , m_hide_my_port(false)
+ , m_network_id(std::move(network_id))
{}
static void init_options(boost::program_options::options_description& desc);
bool run();
- bool init(const boost::program_options::variables_map& vm);
+ bool init(const boost::program_options::variables_map& vm, bool testnet);
bool deinit();
bool send_stop_signal();
uint32_t get_this_peer_port(){return m_listenning_port;}
@@ -149,7 +157,10 @@ namespace nodetool
virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type)> f);
//-----------------------------------------------------------------------------------------------
bool parse_peer_from_string(nodetool::net_address& pe, const std::string& node_addr);
- bool handle_command_line(const boost::program_options::variables_map& vm);
+ bool handle_command_line(
+ const boost::program_options::variables_map& vm
+ , bool testnet
+ );
bool idle_worker();
bool handle_remote_peerlist(const std::list<peerlist_entry>& peerlist, time_t local_time, const epee::net_utils::connection_context_base& context);
bool get_local_node_data(basic_node_data& node_data);
@@ -229,6 +240,7 @@ namespace nodetool
uint64_t m_peer_livetime;
//keep connections to initiate some interactions
net_server m_net_server;
+ boost::uuids::uuid m_network_id;
};
}
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index ee401ce42..870e7572e 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -60,7 +60,16 @@ namespace nodetool
namespace
{
const command_line::arg_descriptor<std::string> arg_p2p_bind_ip = {"p2p-bind-ip", "Interface for p2p network protocol", "0.0.0.0"};
- const command_line::arg_descriptor<std::string> arg_p2p_bind_port = {"p2p-bind-port", "Port for p2p network protocol", boost::to_string(P2P_DEFAULT_PORT)};
+ const command_line::arg_descriptor<std::string> arg_p2p_bind_port = {
+ "p2p-bind-port"
+ , "Port for p2p network protocol"
+ , std::to_string(config::P2P_DEFAULT_PORT)
+ };
+ const command_line::arg_descriptor<std::string> arg_testnet_p2p_bind_port = {
+ "testnet-p2p-bind-port"
+ , "Port for testnet p2p network protocol"
+ , std::to_string(config::testnet::P2P_DEFAULT_PORT)
+ };
const command_line::arg_descriptor<uint32_t> arg_p2p_external_port = {"p2p-external-port", "External port for p2p network protocol (if port forwarding used with NAT)", 0};
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"};
@@ -77,6 +86,7 @@ namespace nodetool
{
command_line::add_arg(desc, arg_p2p_bind_ip);
command_line::add_arg(desc, arg_p2p_bind_port);
+ command_line::add_arg(desc, arg_testnet_p2p_bind_port);
command_line::add_arg(desc, arg_p2p_external_port);
command_line::add_arg(desc, arg_p2p_allow_local_ip);
command_line::add_arg(desc, arg_p2p_add_peer);
@@ -138,10 +148,15 @@ namespace nodetool
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
- bool node_server<t_payload_net_handler>::handle_command_line(const boost::program_options::variables_map& vm)
+ bool node_server<t_payload_net_handler>::handle_command_line(
+ const boost::program_options::variables_map& vm
+ , bool testnet
+ )
{
+ auto p2p_bind_arg = testnet ? arg_testnet_p2p_bind_port : arg_p2p_bind_port;
+
m_bind_ip = command_line::get_arg(vm, arg_p2p_bind_ip);
- m_port = command_line::get_arg(vm, arg_p2p_bind_port);
+ m_port = command_line::get_arg(vm, p2p_bind_arg);
m_external_port = command_line::get_arg(vm, arg_p2p_external_port);
m_allow_local_ip = command_line::get_arg(vm, arg_p2p_allow_local_ip);
@@ -180,67 +195,74 @@ namespace nodetool
return true;
}
//-----------------------------------------------------------------------------------
- namespace
+ inline void add_hardcoded_seed_node(
+ std::vector<net_address> & seed_nodes
+ , std::string const & addr
+ )
{
- template<typename T>
- bool append_net_address(T& nodes, const std::string& addr)
+ using namespace boost::asio;
+
+ size_t pos = addr.find_last_of(':');
+ CHECK_AND_ASSERT_MES_NO_RET(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, "Failed to parse seed address from string: '" << addr << '\'');
+ std::string host = addr.substr(0, pos);
+ std::string port = addr.substr(pos + 1);
+
+ io_service io_srv;
+ ip::tcp::resolver resolver(io_srv);
+ ip::tcp::resolver::query query(host, port);
+ boost::system::error_code ec;
+ ip::tcp::resolver::iterator i = resolver.resolve(query, ec);
+ CHECK_AND_ASSERT_MES_NO_RET(!ec, "Failed to resolve host name '" << host << "': " << ec.message() << ':' << ec.value());
+
+ ip::tcp::resolver::iterator iend;
+ for (; i != iend; ++i)
{
- using namespace boost::asio;
-
- size_t pos = addr.find_last_of(':');
- CHECK_AND_ASSERT_MES(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, false, "Failed to parse seed address from string: '" << addr << '\'');
- std::string host = addr.substr(0, pos);
- std::string port = addr.substr(pos + 1);
-
- io_service io_srv;
- ip::tcp::resolver resolver(io_srv);
- ip::tcp::resolver::query query(host, port);
- boost::system::error_code ec;
- ip::tcp::resolver::iterator i = resolver.resolve(query, ec);
- CHECK_AND_NO_ASSERT_MES(!ec, false, "Failed to resolve host name '" << host << "': " << ec.message() << ':' << ec.value());
-
- ip::tcp::resolver::iterator iend;
- for (; i != iend; ++i)
+ ip::tcp::endpoint endpoint = *i;
+ if (endpoint.address().is_v4())
{
- ip::tcp::endpoint endpoint = *i;
- if (endpoint.address().is_v4())
- {
- nodetool::net_address na;
- na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong());
- na.port = endpoint.port();
- nodes.push_back(na);
- LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port);
- }
- else
- {
- LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec));
- }
+ nodetool::net_address na;
+ na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong());
+ na.port = endpoint.port();
+ seed_nodes.push_back(na);
+ LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port);
+ }
+ else
+ {
+ LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec));
}
-
- return true;
}
}
- #define ADD_HARDCODED_SEED_NODE(addr) append_net_address(m_seed_nodes, addr);
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
- bool node_server<t_payload_net_handler>::init(const boost::program_options::variables_map& vm)
+ bool node_server<t_payload_net_handler>::init(const boost::program_options::variables_map& vm, bool testnet)
{
- ADD_HARDCODED_SEED_NODE("62.210.78.186:18080");
- ADD_HARDCODED_SEED_NODE("195.12.60.154:18080");
- ADD_HARDCODED_SEED_NODE("54.241.246.125:18080");
- ADD_HARDCODED_SEED_NODE("107.170.157.169:18080");
- ADD_HARDCODED_SEED_NODE("54.207.112.216:18080");
- ADD_HARDCODED_SEED_NODE("78.27.112.54:18080");
- ADD_HARDCODED_SEED_NODE("209.222.30.57:18080");
- ADD_HARDCODED_SEED_NODE("80.71.13.55:18080");
- ADD_HARDCODED_SEED_NODE("107.178.112.126:18080");
- ADD_HARDCODED_SEED_NODE("107.158.233.98:18080");
- ADD_HARDCODED_SEED_NODE("64.22.111.2:18080");
-
- bool res = handle_command_line(vm);
+ if (testnet)
+ {
+ add_hardcoded_seed_node(m_seed_nodes, "107.152.187.202:28080");
+ add_hardcoded_seed_node(m_seed_nodes, "197.242.158.240:28080");
+ add_hardcoded_seed_node(m_seed_nodes, "107.152.130.98:28080");
+ }
+ else
+ {
+ add_hardcoded_seed_node(m_seed_nodes, "62.210.78.186:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "195.12.60.154:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "54.241.246.125:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "107.170.157.169:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "54.207.112.216:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "78.27.112.54:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "209.222.30.57:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "80.71.13.55:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "107.178.112.126:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "107.158.233.98:18080");
+ add_hardcoded_seed_node(m_seed_nodes, "64.22.111.2:18080");
+ }
+
+ bool res = handle_command_line(vm, testnet);
CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line");
- m_config_folder = command_line::get_arg(vm, command_line::arg_data_dir);
+
+ auto config_arg = testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
+ m_config_folder = command_line::get_arg(vm, config_arg);
res = init_config();
CHECK_AND_ASSERT_MES(res, false, "Failed to init config.");
@@ -410,7 +432,7 @@ namespace nodetool
return;
}
- if(rsp.node_data.network_id != MONERO_NETWORK)
+ if(rsp.node_data.network_id != m_network_id)
{
LOG_ERROR_CCONTEXT("COMMAND_HANDSHAKE Failed, wrong network! (" << epee::string_tools::get_str_from_guid_a(rsp.node_data.network_id) << "), closing connection.");
return;
@@ -818,7 +840,7 @@ namespace nodetool
node_data.my_port = m_external_port ? m_external_port : m_listenning_port;
else
node_data.my_port = 0;
- node_data.network_id = MONERO_NETWORK;
+ node_data.network_id = m_network_id;
return true;
}
//-----------------------------------------------------------------------------------
@@ -844,7 +866,7 @@ namespace nodetool
return false;
}
crypto::public_key pk = AUTO_VAL_INIT(pk);
- epee::string_tools::hex_to_pod(P2P_STAT_TRUSTED_PUB_KEY, pk);
+ epee::string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pk);
crypto::hash h = tools::get_proof_of_trust_hash(tr);
if(!crypto::check_signature(h, pk, tr.sign))
{
@@ -1038,7 +1060,7 @@ namespace nodetool
template<class t_payload_net_handler>
int node_server<t_payload_net_handler>::handle_handshake(int command, typename COMMAND_HANDSHAKE::request& arg, typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context)
{
- if(arg.node_data.network_id != MONERO_NETWORK)
+ if(arg.node_data.network_id != m_network_id)
{
LOG_PRINT_CCONTEXT_L1("WRONG NETWORK AGENT CONNECTED! id=" << epee::string_tools::get_str_from_guid_a(arg.node_data.network_id));
diff --git a/src/p2p/p2p_networks.h b/src/p2p/p2p_networks.h
deleted file mode 100644
index b3193ee6a..000000000
--- a/src/p2p/p2p_networks.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2014, The Monero Project
-//
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-// conditions and the following disclaimer.
-//
-// 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.
-//
-// 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.
-//
-// 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.
-//
-// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-
-#pragma once
-
-namespace nodetool
-{
- const static boost::uuids::uuid MONERO_NETWORK = { { 0x12 ,0x30, 0xF1, 0x71 , 0x61, 0x04 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10} }; //Bender's nightmare
-}