diff options
Diffstat (limited to 'src/p2p')
-rw-r--r-- | src/p2p/net_node.cpp | 15 | ||||
-rw-r--r-- | src/p2p/net_node.h | 8 | ||||
-rw-r--r-- | src/p2p/net_node.inl | 15 | ||||
-rw-r--r-- | src/p2p/net_peerlist_boost_serialization.h | 47 | ||||
-rw-r--r-- | src/p2p/p2p_protocol_defs.h | 1 |
5 files changed, 73 insertions, 13 deletions
diff --git a/src/p2p/net_node.cpp b/src/p2p/net_node.cpp index 8639fdb3b..2f0678913 100644 --- a/src/p2p/net_node.cpp +++ b/src/p2p/net_node.cpp @@ -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..58e3c8857 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -129,7 +129,7 @@ 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 { @@ -437,8 +437,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 +463,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..e3d804086 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -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); @@ -2456,13 +2457,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 +2471,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 +2481,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_peerlist_boost_serialization.h b/src/p2p/net_peerlist_boost_serialization.h index d2e9efa3d..6c891581f 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-2018, 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..e9449b950 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -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" |