diff options
Diffstat (limited to 'src/p2p')
-rw-r--r-- | src/p2p/net_node.cpp | 15 | ||||
-rw-r--r-- | src/p2p/net_peerlist_boost_serialization.h | 47 | ||||
-rw-r--r-- | src/p2p/p2p_protocol_defs.h | 1 |
3 files changed, 60 insertions, 3 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_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" |