diff options
author | Jethro Grassie <jtg@xtrabass.com> | 2019-01-21 11:50:03 -0500 |
---|---|---|
committer | Jethro Grassie <jtg@xtrabass.com> | 2019-01-30 13:37:45 -0500 |
commit | 123fc2a25afaebe89b94c9806eb05033e021d807 (patch) | |
tree | 2151ced1046c2b1e40c8c123fa60d2d38ba0df7f /src/p2p/net_peerlist_boost_serialization.h | |
parent | Merge pull request #4988 (diff) | |
download | monero-123fc2a25afaebe89b94c9806eb05033e021d807.tar.xz |
i2p: initial support
Diffstat (limited to 'src/p2p/net_peerlist_boost_serialization.h')
-rw-r--r-- | src/p2p/net_peerlist_boost_serialization.h | 47 |
1 files changed, 46 insertions, 1 deletions
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; |