aboutsummaryrefslogtreecommitdiff
path: root/src/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'src/p2p')
-rw-r--r--src/p2p/CMakeLists.txt2
-rw-r--r--src/p2p/net_node.cpp17
-rw-r--r--src/p2p/net_node.h15
-rw-r--r--src/p2p/net_node.inl27
-rw-r--r--src/p2p/net_node_common.h2
-rw-r--r--src/p2p/net_peerlist.h2
-rw-r--r--src/p2p/net_peerlist_boost_serialization.h47
-rw-r--r--src/p2p/p2p_protocol_defs.h47
-rw-r--r--src/p2p/stdafx.h2
9 files changed, 122 insertions, 39 deletions
diff --git a/src/p2p/CMakeLists.txt b/src/p2p/CMakeLists.txt
index 9a1730b8a..3aecc3cf9 100644
--- a/src/p2p/CMakeLists.txt
+++ b/src/p2p/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/p2p/net_node.cpp b/src/p2p/net_node.cpp
index 8639fdb3b..e0f1de14a 100644
--- a/src/p2p/net_node.cpp
+++ b/src/p2p/net_node.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -46,13 +46,14 @@
#include "net/socks.h"
#include "net/parse.h"
#include "net/tor_address.h"
+#include "net/i2p_address.h"
#include "p2p/p2p_protocol_defs.h"
#include "string_tools.h"
namespace
{
constexpr const boost::chrono::milliseconds future_poll_interval{500};
- constexpr const std::chrono::seconds tor_connect_timeout{P2P_DEFAULT_TOR_CONNECT_TIMEOUT};
+ constexpr const std::chrono::seconds socks_connect_timeout{P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT};
std::int64_t get_max_connections(const boost::iterator_range<boost::string_ref::const_iterator> value) noexcept
{
@@ -90,6 +91,9 @@ namespace
case net::tor_address::get_type_id():
set = client->set_connect_command(remote.as<net::tor_address>());
break;
+ case net::i2p_address::get_type_id():
+ set = client->set_connect_command(remote.as<net::i2p_address>());
+ break;
default:
MERROR("Unsupported network address in socks_connect");
return false;
@@ -177,6 +181,9 @@ namespace nodetool
case epee::net_utils::zone::tor:
proxies.back().zone = epee::net_utils::zone::tor;
break;
+ case epee::net_utils::zone::i2p:
+ proxies.back().zone = epee::net_utils::zone::i2p;
+ break;
default:
MERROR("Invalid network for --" << arg_proxy.name);
return boost::none;
@@ -235,6 +242,10 @@ namespace nodetool
inbounds.back().our_address = std::move(*our_address);
inbounds.back().default_remote = net::tor_address::unknown();
break;
+ case net::i2p_address::get_type_id():
+ inbounds.back().our_address = std::move(*our_address);
+ inbounds.back().default_remote = net::i2p_address::unknown();
+ break;
default:
MERROR("Invalid inbound address (" << address << ") for --" << arg_anonymous_inbound.name << ": " << (our_address ? "invalid type" : our_address.error().message()));
return boost::none;
@@ -308,7 +319,7 @@ namespace nodetool
const auto start = std::chrono::steady_clock::now();
while (socks_result.wait_for(future_poll_interval) == boost::future_status::timeout)
{
- if (tor_connect_timeout < std::chrono::steady_clock::now() - start)
+ if (socks_connect_timeout < std::chrono::steady_clock::now() - start)
{
MERROR("Timeout on socks connect (" << proxy << " to " << remote.str() << ")");
return boost::none;
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 112f30fb6..0e7016b27 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -129,11 +129,11 @@ namespace nodetool
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&);
+ using connect_func = boost::optional<p2p_connection_context>(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
- struct config
+ struct config_t
{
- config()
+ config_t()
: m_net_config(),
m_peer_id(crypto::rand<uint64_t>()),
m_support_flags(0)
@@ -143,6 +143,7 @@ namespace nodetool
uint64_t m_peer_id;
uint32_t m_support_flags;
};
+ typedef epee::misc_utils::struct_init<config_t> config;
struct network_zone
{
@@ -437,8 +438,8 @@ namespace nodetool
//keep connections to initiate some interactions
- 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&);
+ static boost::optional<p2p_connection_context> public_connect(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
+ static boost::optional<p2p_connection_context> socks_connect(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
/* A `std::map` provides constant iterators and key/value pointers even with
@@ -463,6 +464,8 @@ namespace nodetool
boost::uuids::uuid m_network_id;
cryptonote::network_type m_nettype;
+
+ epee::net_utils::ssl_support_t m_ssl_support;
};
const int64_t default_limit_up = P2P_DEFAULT_LIMIT_RATE_UP; // kB/s
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 471fdda0d..f32b9e990 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -650,6 +650,7 @@ namespace nodetool
return res;
//try to bind
+ m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_disabled;
for (auto& zone : m_network_zones)
{
zone.second.m_net_server.get_config_object().set_handler(this);
@@ -659,7 +660,7 @@ namespace nodetool
{
zone.second.m_net_server.set_connection_filter(this);
MINFO("Binding on " << zone.second.m_bind_ip << ":" << zone.second.m_port);
- res = zone.second.m_net_server.init_server(zone.second.m_port, zone.second.m_bind_ip);
+ res = zone.second.m_net_server.init_server(zone.second.m_port, zone.second.m_bind_ip, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
CHECK_AND_ASSERT_MES(res, false, "Failed to bind server");
}
}
@@ -1057,7 +1058,7 @@ namespace nodetool
<< (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never")
<< ")...");
- auto con = zone.m_connect(zone, na);
+ auto con = zone.m_connect(zone, na, m_ssl_support);
if(!con)
{
bool is_priority = is_priority_node(na);
@@ -1119,7 +1120,7 @@ namespace nodetool
<< (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never")
<< ")...");
- auto con = zone.m_connect(zone, na);
+ auto con = zone.m_connect(zone, na, m_ssl_support);
if (!con) {
bool is_priority = is_priority_node(na);
@@ -1397,7 +1398,15 @@ namespace nodetool
}
if(zone.second.m_net_server.is_stop_signal_sent())
return false;
- conn_count = get_outgoing_connections_count(zone.second);
+ size_t new_conn_count = get_outgoing_connections_count(zone.second);
+ if (new_conn_count <= conn_count)
+ {
+ // we did not make any connection, sleep a bit to avoid a busy loop in case we don't have
+ // any peers to try, then break so we will try seeds to get more peers
+ boost::this_thread::sleep_for(boost::chrono::seconds(1));
+ break;
+ }
+ conn_count = new_conn_count;
}
}
@@ -2456,13 +2465,13 @@ namespace nodetool
template<typename t_payload_net_handler>
boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
- node_server<t_payload_net_handler>::socks_connect(network_zone& zone, const epee::net_utils::network_address& remote)
+ node_server<t_payload_net_handler>::socks_connect(network_zone& zone, const epee::net_utils::network_address& remote, epee::net_utils::ssl_support_t ssl_support)
{
auto result = socks_connect_internal(zone.m_net_server.get_stop_signal(), zone.m_net_server.get_io_service(), zone.m_proxy_address, remote);
if (result) // if no error
{
p2p_connection_context context{};
- if (zone.m_net_server.add_connection(context, std::move(*result), remote))
+ if (zone.m_net_server.add_connection(context, std::move(*result), remote, ssl_support))
return {std::move(context)};
}
return boost::none;
@@ -2470,7 +2479,7 @@ namespace nodetool
template<typename t_payload_net_handler>
boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
- node_server<t_payload_net_handler>::public_connect(network_zone& zone, epee::net_utils::network_address const& na)
+ node_server<t_payload_net_handler>::public_connect(network_zone& zone, epee::net_utils::network_address const& na, epee::net_utils::ssl_support_t ssl_support)
{
CHECK_AND_ASSERT_MES(na.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id(), boost::none,
"Only IPv4 addresses are supported here");
@@ -2480,7 +2489,7 @@ namespace nodetool
const bool res = zone.m_net_server.connect(epee::string_tools::get_ip_string_from_int32(ipv4.ip()),
epee::string_tools::num_to_string_fast(ipv4.port()),
zone.m_config.m_net_config.connection_timeout,
- con);
+ con, "0.0.0.0", ssl_support);
if (res)
return {std::move(con)};
diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h
index 944bf48e4..26451b333 100644
--- a/src/p2p/net_node_common.h
+++ b/src/p2p/net_node_common.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index 46726d7d8..91d7fa2b3 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/p2p/net_peerlist_boost_serialization.h b/src/p2p/net_peerlist_boost_serialization.h
index d2e9efa3d..1d6eb7690 100644
--- a/src/p2p/net_peerlist_boost_serialization.h
+++ b/src/p2p/net_peerlist_boost_serialization.h
@@ -1,4 +1,4 @@
- // Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -35,6 +35,7 @@
#include "common/expect.h"
#include "net/net_utils_base.h"
#include "net/tor_address.h"
+#include "net/i2p_address.h"
#include "p2p/p2p_protocol_defs.h"
#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
@@ -76,6 +77,9 @@ namespace boost
case net::tor_address::get_type_id():
do_serialize<net::tor_address>(is_saving, a, na);
break;
+ case net::i2p_address::get_type_id():
+ do_serialize<net::i2p_address>(is_saving, a, na);
+ break;
case epee::net_utils::address_type::invalid:
default:
throw std::runtime_error("Unsupported network address type");
@@ -107,6 +111,20 @@ namespace boost
}
template <class Archive, class ver_type>
+ inline void save(Archive& a, const net::i2p_address& na, const ver_type)
+ {
+ const size_t length = std::strlen(na.host_str());
+ if (length > 255)
+ MONERO_THROW(net::error::invalid_i2p_address, "i2p address too long");
+
+ const uint16_t port{na.port()};
+ const uint8_t len = length;
+ a & port;
+ a & len;
+ a.save_binary(na.host_str(), length);
+ }
+
+ template <class Archive, class ver_type>
inline void load(Archive& a, net::tor_address& na, const ver_type)
{
uint16_t port = 0;
@@ -128,12 +146,39 @@ namespace boost
}
template <class Archive, class ver_type>
+ inline void load(Archive& a, net::i2p_address& na, const ver_type)
+ {
+ uint16_t port = 0;
+ uint8_t length = 0;
+ a & port;
+ a & length;
+
+ if (length > net::i2p_address::buffer_size())
+ MONERO_THROW(net::error::invalid_i2p_address, "i2p address too long");
+
+ char host[net::i2p_address::buffer_size()] = {0};
+ a.load_binary(host, length);
+ host[sizeof(host) - 1] = 0;
+
+ if (std::strcmp(host, net::i2p_address::unknown_str()) == 0)
+ na = net::i2p_address::unknown();
+ else
+ na = MONERO_UNWRAP(net::i2p_address::make(host, port));
+ }
+
+ template <class Archive, class ver_type>
inline void serialize(Archive &a, net::tor_address& na, const ver_type ver)
{
boost::serialization::split_free(a, na, ver);
}
template <class Archive, class ver_type>
+ inline void serialize(Archive &a, net::i2p_address& na, const ver_type ver)
+ {
+ boost::serialization::split_free(a, na, ver);
+ }
+
+ template <class Archive, class ver_type>
inline void serialize(Archive &a, nodetool::peerlist_entry& pl, const ver_type ver)
{
a & pl.adr;
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index 6e5e45008..b08fc7e83 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -35,6 +35,7 @@
#include "serialization/keyvalue_serialization.h"
#include "net/net_utils_base.h"
#include "net/tor_address.h" // needed for serialization
+#include "net/i2p_address.h" // needed for serialization
#include "misc_language.h"
#include "string_tools.h"
#include "time_helper.h"
@@ -178,7 +179,7 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 1;
- struct request
+ struct request_t
{
basic_node_data node_data;
t_playload_type payload_data;
@@ -188,8 +189,9 @@ namespace nodetool
KV_SERIALIZE(payload_data)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
basic_node_data node_data;
t_playload_type payload_data;
@@ -229,7 +231,8 @@ namespace nodetool
}
END_KV_SERIALIZE_MAP()
};
- };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
/************************************************************************/
@@ -240,15 +243,16 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 2;
- struct request
+ struct request_t
{
t_playload_type payload_data;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(payload_data)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t local_time;
t_playload_type payload_data;
@@ -288,6 +292,7 @@ namespace nodetool
}
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
/************************************************************************/
@@ -305,15 +310,16 @@ namespace nodetool
#define PING_OK_RESPONSE_STATUS_TEXT "OK"
- struct request
+ struct request_t
{
/*actually we don't need to send any real data*/
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
peerid_type peer_id;
@@ -323,6 +329,7 @@ namespace nodetool
KV_SERIALIZE(peer_id)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
@@ -349,15 +356,16 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 4;
- struct request
+ struct request_t
{
proof_of_trust tr;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tr)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string version;
std::string os_version;
@@ -373,6 +381,7 @@ namespace nodetool
KV_SERIALIZE(payload_info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
@@ -383,15 +392,16 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 5;
- struct request
+ struct request_t
{
proof_of_trust tr;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tr)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::vector<peerlist_entry> local_peerlist_white;
std::vector<peerlist_entry> local_peerlist_gray;
@@ -406,6 +416,7 @@ namespace nodetool
KV_SERIALIZE(local_time)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
/************************************************************************/
@@ -415,13 +426,14 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 6;
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
peerid_type my_id;
@@ -429,6 +441,7 @@ namespace nodetool
KV_SERIALIZE(my_id)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
/************************************************************************/
@@ -438,13 +451,14 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 7;
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint32_t support_flags;
@@ -452,6 +466,7 @@ namespace nodetool
KV_SERIALIZE(support_flags)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
#endif
diff --git a/src/p2p/stdafx.h b/src/p2p/stdafx.h
index b6ff37811..12a371702 100644
--- a/src/p2p/stdafx.h
+++ b/src/p2p/stdafx.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//