2019-03-05 21:05:34 +00:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
2014-07-23 13:03:52 +00:00
|
|
|
//
|
|
|
|
// 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
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-12-16 17:57:44 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "common/expect.h"
|
2017-05-27 10:35:54 +00:00
|
|
|
#include "net/net_utils_base.h"
|
2018-12-16 17:57:44 +00:00
|
|
|
#include "net/tor_address.h"
|
2019-01-21 16:50:03 +00:00
|
|
|
#include "net/i2p_address.h"
|
2017-08-25 15:14:46 +00:00
|
|
|
#include "p2p/p2p_protocol_defs.h"
|
2017-05-27 10:35:54 +00:00
|
|
|
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
|
|
|
|
#include "common/pruning.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-24 08:47:49 +00:00
|
|
|
BOOST_CLASS_VERSION(nodetool::peerlist_entry, 2)
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
namespace serialization
|
|
|
|
{
|
2017-08-25 15:14:46 +00:00
|
|
|
template <class T, class Archive>
|
2018-12-16 17:57:44 +00:00
|
|
|
inline void do_serialize(boost::mpl::false_, Archive &a, epee::net_utils::network_address& na)
|
2017-08-25 15:14:46 +00:00
|
|
|
{
|
2018-12-16 17:57:44 +00:00
|
|
|
T addr{};
|
|
|
|
a & addr;
|
|
|
|
na = std::move(addr);
|
2017-08-25 15:14:46 +00:00
|
|
|
}
|
2018-12-16 17:57:44 +00:00
|
|
|
|
|
|
|
template <class T, class Archive>
|
|
|
|
inline void do_serialize(boost::mpl::true_, Archive &a, const epee::net_utils::network_address& na)
|
|
|
|
{
|
|
|
|
a & na.as<T>();
|
|
|
|
}
|
|
|
|
|
2017-05-27 10:35:54 +00:00
|
|
|
template <class Archive, class ver_type>
|
|
|
|
inline void serialize(Archive &a, epee::net_utils::network_address& na, const ver_type ver)
|
|
|
|
{
|
2018-12-16 17:57:44 +00:00
|
|
|
static constexpr const typename Archive::is_saving is_saving{};
|
|
|
|
|
2017-05-27 10:35:54 +00:00
|
|
|
uint8_t type;
|
2018-12-16 17:57:44 +00:00
|
|
|
if (is_saving)
|
|
|
|
type = uint8_t(na.get_type_id());
|
2017-05-27 10:35:54 +00:00
|
|
|
a & type;
|
2018-12-16 17:57:44 +00:00
|
|
|
switch (epee::net_utils::address_type(type))
|
2017-05-27 10:35:54 +00:00
|
|
|
{
|
2018-12-16 17:57:44 +00:00
|
|
|
case epee::net_utils::ipv4_network_address::get_type_id():
|
|
|
|
do_serialize<epee::net_utils::ipv4_network_address>(is_saving, a, na);
|
|
|
|
break;
|
|
|
|
case net::tor_address::get_type_id():
|
|
|
|
do_serialize<net::tor_address>(is_saving, a, na);
|
|
|
|
break;
|
2019-01-21 16:50:03 +00:00
|
|
|
case net::i2p_address::get_type_id():
|
|
|
|
do_serialize<net::i2p_address>(is_saving, a, na);
|
|
|
|
break;
|
2018-12-16 17:57:44 +00:00
|
|
|
case epee::net_utils::address_type::invalid:
|
2017-05-27 10:35:54 +00:00
|
|
|
default:
|
|
|
|
throw std::runtime_error("Unsupported network address type");
|
|
|
|
}
|
|
|
|
}
|
2014-03-03 22:07:58 +00:00
|
|
|
template <class Archive, class ver_type>
|
2017-05-27 10:35:54 +00:00
|
|
|
inline void serialize(Archive &a, epee::net_utils::ipv4_network_address& na, const ver_type ver)
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
2017-08-25 15:14:46 +00:00
|
|
|
uint32_t ip{na.ip()};
|
|
|
|
uint16_t port{na.port()};
|
|
|
|
a & ip;
|
|
|
|
a & port;
|
2017-08-23 12:32:02 +00:00
|
|
|
if (!typename Archive::is_saving())
|
2017-08-25 15:14:46 +00:00
|
|
|
na = epee::net_utils::ipv4_network_address{ip, port};
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 17:57:44 +00:00
|
|
|
template <class Archive, class ver_type>
|
|
|
|
inline void save(Archive& a, const net::tor_address& na, const ver_type)
|
|
|
|
{
|
|
|
|
const size_t length = std::strlen(na.host_str());
|
|
|
|
if (length > 255)
|
|
|
|
MONERO_THROW(net::error::invalid_tor_address, "Tor 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);
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:50:03 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-12-16 17:57:44 +00:00
|
|
|
template <class Archive, class ver_type>
|
|
|
|
inline void load(Archive& a, net::tor_address& na, const ver_type)
|
|
|
|
{
|
|
|
|
uint16_t port = 0;
|
|
|
|
uint8_t length = 0;
|
|
|
|
a & port;
|
|
|
|
a & length;
|
|
|
|
|
2019-06-08 15:58:09 +00:00
|
|
|
const size_t buffer_size = net::tor_address::buffer_size();
|
|
|
|
if (length > buffer_size)
|
2018-12-16 17:57:44 +00:00
|
|
|
MONERO_THROW(net::error::invalid_tor_address, "Tor address too long");
|
|
|
|
|
2019-06-08 15:58:09 +00:00
|
|
|
char host[buffer_size] = {0};
|
2018-12-16 17:57:44 +00:00
|
|
|
a.load_binary(host, length);
|
|
|
|
host[sizeof(host) - 1] = 0;
|
|
|
|
|
|
|
|
if (std::strcmp(host, net::tor_address::unknown_str()) == 0)
|
|
|
|
na = net::tor_address::unknown();
|
|
|
|
else
|
|
|
|
na = MONERO_UNWRAP(net::tor_address::make(host, port));
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:50:03 +00:00
|
|
|
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;
|
|
|
|
|
2019-06-08 15:58:09 +00:00
|
|
|
const size_t buffer_size = net::i2p_address::buffer_size();
|
|
|
|
if (length > buffer_size)
|
2019-01-21 16:50:03 +00:00
|
|
|
MONERO_THROW(net::error::invalid_i2p_address, "i2p address too long");
|
|
|
|
|
2019-06-08 15:58:09 +00:00
|
|
|
char host[buffer_size] = {0};
|
2019-01-21 16:50:03 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2018-12-16 17:57:44 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:50:03 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
template <class Archive, class ver_type>
|
|
|
|
inline void serialize(Archive &a, nodetool::peerlist_entry& pl, const ver_type ver)
|
|
|
|
{
|
|
|
|
a & pl.adr;
|
|
|
|
a & pl.id;
|
|
|
|
a & pl.last_seen;
|
Pruning
The blockchain prunes seven eighths of prunable tx data.
This saves about two thirds of the blockchain size, while
keeping the node useful as a sync source for an eighth
of the blockchain.
No other data is currently pruned.
There are three ways to prune a blockchain:
- run monerod with --prune-blockchain
- run "prune_blockchain" in the monerod console
- run the monero-blockchain-prune utility
The first two will prune in place. Due to how LMDB works, this
will not reduce the blockchain size on disk. Instead, it will
mark parts of the file as free, so that future data will use
that free space, causing the file to not grow until free space
grows scarce.
The third way will create a second database, a pruned copy of
the original one. Since this is a new file, this one will be
smaller than the original one.
Once the database is pruned, it will stay pruned as it syncs.
That is, there is no need to use --prune-blockchain again, etc.
2018-04-29 22:30:51 +00:00
|
|
|
if (ver < 1)
|
|
|
|
{
|
|
|
|
if (!typename Archive::is_saving())
|
|
|
|
pl.pruning_seed = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
a & pl.pruning_seed;
|
|
|
|
#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
|
|
|
|
if (!typename Archive::is_saving())
|
|
|
|
{
|
|
|
|
pl.pruning_seed = tools::make_pruning_seed(1+pl.adr.as<epee::net_utils::ipv4_network_address>().ip() % (1<<CRYPTONOTE_PRUNING_LOG_STRIPES), CRYPTONOTE_PRUNING_LOG_STRIPES);
|
|
|
|
}
|
|
|
|
#endif
|
2019-02-24 08:47:49 +00:00
|
|
|
if (ver < 2)
|
|
|
|
{
|
|
|
|
if (!typename Archive::is_saving())
|
|
|
|
pl.rpc_port = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
a & pl.rpc_port;
|
2017-02-09 00:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Archive, class ver_type>
|
|
|
|
inline void serialize(Archive &a, nodetool::anchor_peerlist_entry& pl, const ver_type ver)
|
|
|
|
{
|
|
|
|
a & pl.adr;
|
|
|
|
a & pl.id;
|
|
|
|
a & pl.first_seen;
|
|
|
|
}
|
2014-03-03 22:07:58 +00:00
|
|
|
}
|
|
|
|
}
|