2019-04-12 06:36:43 +02:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
2015-12-14 05:54:39 +01:00
|
|
|
//
|
2014-07-23 15:03:52 +02:00
|
|
|
// All rights reserved.
|
2015-12-14 05:54:39 +01:00
|
|
|
//
|
2014-07-23 15:03:52 +02:00
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
2015-12-14 05:54:39 +01:00
|
|
|
//
|
2014-07-23 15:03:52 +02:00
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
2015-12-14 05:54:39 +01:00
|
|
|
//
|
2014-07-23 15:03:52 +02:00
|
|
|
// 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.
|
2015-12-14 05:54:39 +01:00
|
|
|
//
|
2014-07-23 15:03:52 +02:00
|
|
|
// 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.
|
2015-12-14 05:54:39 +01:00
|
|
|
//
|
2014-07-23 15:03:52 +02:00
|
|
|
// 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.
|
2015-12-14 05:54:39 +01:00
|
|
|
//
|
2014-07-23 15:03:52 +02:00
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
2014-03-03 23:07:58 +01:00
|
|
|
|
|
|
|
#pragma once
|
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-30 00:30:51 +02:00
|
|
|
#include <array>
|
2019-04-09 10:07:13 +02:00
|
|
|
#include <atomic>
|
|
|
|
#include <boost/asio/io_service.hpp>
|
|
|
|
#include <boost/asio/ip/tcp.hpp>
|
2014-03-03 23:07:58 +01:00
|
|
|
#include <boost/program_options/options_description.hpp>
|
|
|
|
#include <boost/program_options/variables_map.hpp>
|
2014-09-08 19:40:28 +02:00
|
|
|
#include <boost/uuid/uuid.hpp>
|
2019-04-09 10:07:13 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2020-07-13 03:15:35 +02:00
|
|
|
#include <shared_mutex>
|
2014-03-03 23:07:58 +01:00
|
|
|
|
2014-09-05 04:14:36 +02:00
|
|
|
#include "cryptonote_config.h"
|
2019-05-16 22:34:22 +02:00
|
|
|
#include "cryptonote_protocol/levin_notify.h"
|
2014-03-03 23:07:58 +01:00
|
|
|
#include "warnings.h"
|
2018-11-15 17:29:34 +01:00
|
|
|
#include "net/abstract_tcp_server2.h"
|
|
|
|
#include "net/levin_protocol_handler.h"
|
|
|
|
#include "net/levin_protocol_handler_async.h"
|
2014-03-03 23:07:58 +01:00
|
|
|
#include "p2p_protocol_defs.h"
|
|
|
|
#include "storages/levin_abstract_invoke2.h"
|
|
|
|
#include "net_peerlist.h"
|
|
|
|
#include "net_node_common.h"
|
2019-04-09 10:07:13 +02:00
|
|
|
#include "net/enums.h"
|
|
|
|
#include "net/fwd.h"
|
2014-05-25 19:06:40 +02:00
|
|
|
#include "common/command_line.h"
|
2020-05-26 07:15:25 +02:00
|
|
|
#include "common/periodic_task.h"
|
2014-03-03 23:07:58 +01:00
|
|
|
|
|
|
|
PUSH_WARNINGS
|
|
|
|
DISABLE_VS_WARNINGS(4355)
|
|
|
|
|
|
|
|
namespace nodetool
|
|
|
|
{
|
2019-04-09 10:07:13 +02:00
|
|
|
struct proxy
|
|
|
|
{
|
|
|
|
proxy()
|
|
|
|
: max_connections(-1),
|
|
|
|
address(),
|
2019-05-16 22:34:22 +02:00
|
|
|
zone(epee::net_utils::zone::invalid),
|
|
|
|
noise(true)
|
2019-04-09 10:07:13 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
std::int64_t max_connections;
|
|
|
|
boost::asio::ip::tcp::endpoint address;
|
|
|
|
epee::net_utils::zone zone;
|
2019-05-16 22:34:22 +02:00
|
|
|
bool noise;
|
2019-04-09 10:07:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct anonymous_inbound
|
|
|
|
{
|
|
|
|
anonymous_inbound()
|
|
|
|
: max_connections(-1),
|
|
|
|
local_ip(),
|
|
|
|
local_port(),
|
|
|
|
our_address(),
|
|
|
|
default_remote()
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::int64_t max_connections;
|
|
|
|
std::string local_ip;
|
|
|
|
std::string local_port;
|
|
|
|
epee::net_utils::network_address our_address;
|
|
|
|
epee::net_utils::network_address default_remote;
|
|
|
|
};
|
|
|
|
|
2020-06-02 00:30:19 +02:00
|
|
|
std::optional<std::vector<proxy>> get_proxies(const boost::program_options::variables_map& vm);
|
|
|
|
std::optional<std::vector<anonymous_inbound>> get_anonymous_inbounds(const boost::program_options::variables_map& vm);
|
2019-04-09 10:07:13 +02:00
|
|
|
|
|
|
|
//! \return True if `commnd` is filtered (ignored/dropped) for `address`
|
|
|
|
bool is_filtered_command(epee::net_utils::network_address const& address, int command);
|
|
|
|
|
|
|
|
// hides boost::future and chrono stuff from mondo template file
|
2020-06-02 00:30:19 +02:00
|
|
|
std::optional<boost::asio::ip::tcp::socket>
|
2019-04-09 10:07:13 +02:00
|
|
|
socks_connect_internal(const std::atomic<bool>& stop_signal, boost::asio::io_service& service, const boost::asio::ip::tcp::endpoint& proxy, const epee::net_utils::network_address& remote);
|
|
|
|
|
|
|
|
|
2014-03-03 23:07:58 +01:00
|
|
|
template<class base_type>
|
|
|
|
struct p2p_connection_context_t: base_type //t_payload_net_handler::connection_context //public net_utils::connection_context_base
|
|
|
|
{
|
2017-08-08 18:23:02 +02:00
|
|
|
p2p_connection_context_t(): peer_id(0), support_flags(0), m_in_timedsync(false) {}
|
2017-07-29 12:17:43 +02:00
|
|
|
|
2014-03-03 23:07:58 +01:00
|
|
|
peerid_type peer_id;
|
2016-10-26 21:00:08 +02:00
|
|
|
uint32_t support_flags;
|
2017-07-29 12:17:43 +02:00
|
|
|
bool m_in_timedsync;
|
2019-12-04 22:22:55 +01:00
|
|
|
std::set<epee::net_utils::network_address> sent_addresses;
|
2014-03-03 23:07:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class t_payload_net_handler>
|
2014-05-25 19:06:40 +02:00
|
|
|
class node_server: public epee::levin::levin_commands_handler<p2p_connection_context_t<typename t_payload_net_handler::connection_context> >,
|
2015-11-23 18:34:55 +01:00
|
|
|
public i_p2p_endpoint<typename t_payload_net_handler::connection_context>,
|
|
|
|
public epee::net_utils::i_connection_filter
|
2014-03-03 23:07:58 +01:00
|
|
|
{
|
|
|
|
struct by_conn_id{};
|
|
|
|
struct by_peer_id{};
|
|
|
|
struct by_addr{};
|
|
|
|
|
|
|
|
typedef p2p_connection_context_t<typename t_payload_net_handler::connection_context> p2p_connection_context;
|
|
|
|
|
|
|
|
typedef COMMAND_HANDSHAKE_T<typename t_payload_net_handler::payload_type> COMMAND_HANDSHAKE;
|
|
|
|
typedef COMMAND_TIMED_SYNC_T<typename t_payload_net_handler::payload_type> COMMAND_TIMED_SYNC;
|
|
|
|
|
2019-04-09 10:07:13 +02:00
|
|
|
typedef epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<p2p_connection_context>> net_server;
|
|
|
|
|
|
|
|
struct network_zone;
|
Replace epee http client with curl-based client
In short: epee's http client is garbage, standard violating, and
unreliable.
This completely removes the epee http client support and replaces it
with cpr, a curl-based C++ wrapper. rpc/http_client.h wraps cpr for RPC
requests specifically, but it is also usable directly.
This replacement has a number of advantages:
- requests are considerably more reliable. The epee http client code
assumes that a connection will be kept alive forever, and returns a
failure if a connection is ever closed. This results in some very
annoying things: for example, preparing a transaction and then waiting
a long tim before confirming it will usually result in an error
communication with the daemon. This is just terribly behaviour: the
right thing to do on a connection failure is to resubmit the request.
- epee's http client is broken in lots of other ways: for example, it
tries throwing SSL at the port to see if it is HTTPS, but this is
protocol violating and just breaks (with a several second timeout) on
anything that *isn't* epee http server (for example, when lokid is
behind a proxying server).
- even when it isn't doing the above, the client breaks in other ways:
for example, there is a comment (replaced in this PR) in the Trezor PR
code that forces a connection close after every request because epee's
http client doesn't do proper keep-alive request handling.
- it seems noticeably faster to me in practical use in this PR; both
simple requests (for example, when running `lokid status`) and
wallet<->daemon connections are faster, probably because of crappy
code in epee. (I think this is also related to the throw-ssl-at-it
junk above: the epee client always generates an ssl certificate during
static initialization because it might need one at some point).
- significantly reduces the amount of code we have to maintain.
- removes all the epee ssl option code: curl can handle all of that just
fine.
- removes the epee socks proxy code; curl can handle that just fine.
(And can do more: it also supports using HTTP/HTTPS proxies).
- When a cli wallet connection fails we know show why it failed (which
now is an error message from curl), which could have all sorts of
reasons like hostname resolution failure, bad ssl certificate, etc.
Previously you just got a useless generic error that tells you
nothing.
Other related changes in this PR:
- Drops the check-for-update and download-update code. To the best of
my knowledge these have never been supported in loki-core and so it
didn't seem worth the trouble to convert them to use cpr for the
requests.
- Cleaned up node_rpc_proxy return values: there was an inconsistent mix
of ways to return errors and how the returned strings were handled.
Instead this cleans it up to return a pair<bool, val>, which (with
C++17) can be transparently captured as:
auto [success, val] = node.whatever(req);
This drops the failure message string, but it was almost always set to
something fairly useless (if we want to resurrect it we could easily
change the first element to be a custom type with a bool operator for
success, and a `.error` attribute containing some error string, but
for the most part the current code wasn't doing much useful with the
failure string).
- changed local detection (for automatic trusted daemon determination)
to just look for localhost, and to not try to resolve anything.
Trusting non-public IPs does not work well (e.g. with lokinet where
all .loki addresses resolve to a local IP).
- ssl fingerprint option is removed; this isn't supported by curl
(because it is essentially just duplicating what a custom cainfo
bundle does)
- --daemon-ssl-allow-chained is removed; it wasn't a useful option (if
you don't want chaining, don't specify a cainfo chain).
- --daemon-address is now a URL instead of just host:port. (If you omit
the protocol, http:// is prepended).
- --daemon-host and --daemon-port are now deprecated and produce a
warning (in simplewallet) if used; the replacement is to use
--daemon-address.
- --daemon-ssl is deprecated; specify --daemon-address=https://whatever
instead.
- the above three are now hidden from --help
- reordered the wallet connection options to make more logical sense.
2020-07-26 22:29:49 +02:00
|
|
|
using connect_func = std::optional<p2p_connection_context>(network_zone&, epee::net_utils::network_address const&);
|
2019-04-09 10:07:13 +02:00
|
|
|
|
RPC overhaul
High-level details:
This redesigns the RPC layer to make it much easier to work with,
decouples it from an embedded HTTP server, and gets the vast majority of
the RPC serialization and dispatch code out of a very commonly included
header.
There is unfortunately rather a lot of interconnected code here that
cannot be easily separated out into separate commits. The full details
of what happens here are as follows:
Major details:
- All of the RPC code is now in a `cryptonote::rpc` namespace; this
renames quite a bit to be less verbose: e.g. CORE_RPC_STATUS_OK
becomes `rpc::STATUS_OK`, and `cryptonote::COMMAND_RPC_SOME_LONG_NAME`
becomes `rpc::SOME_LONG_NAME` (or just SOME_LONG_NAME for code already
working in the `rpc` namespace).
- `core_rpc_server` is now completely decoupled from providing any
request protocol: it is now *just* the core RPC call handler.
- The HTTP RPC interface now lives in a new rpc/http_server.h; this code
handles listening for HTTP requests and dispatching them to
core_rpc_server, then sending the results back to the caller.
- There is similarly a rpc/lmq_server.h for LMQ RPC code; more details
on this (and other LMQ specifics) below.
- RPC implementing code now returns the response object and throws when
things go wrong which simplifies much of the rpc error handling. They
can throw anything; generic exceptions get logged and a generic
"internal error" message gets returned to the caller, but there is
also an `rpc_error` class to return an error code and message used by
some json-rpc commands.
- RPC implementing functions now overload `core_rpc_server::invoke`
following the pattern:
RPC_BLAH_BLAH::response core_rpc_server::invoke(RPC_BLAH_BLAH::request&& req, rpc_context context);
This overloading makes the code vastly simpler: all instantiations are
now done with a small amount of generic instantiation code in a single
.cpp rather than needing to go to hell and back with a nest of epee
macros in a core header.
- each RPC endpoint is now defined by the RPC types themselves,
including its accessible names and permissions, in
core_rpc_server_commands_defs.h:
- every RPC structure now has a static `names()` function that returns
the names by which the end point is accessible. (The first one is
the primary, the others are for deprecated aliases).
- RPC command wrappers define their permissions and type by inheriting
from special tag classes:
- rpc::RPC_COMMAND is a basic, admin-only, JSON command, available
via JSON RPC. *All* JSON commands are now available via JSON RPC,
instead of the previous mix of some being at /foo and others at
/json_rpc. (Ones that were previously at /foo are still there for
backwards compatibility; see `rpc::LEGACY` below).
- rpc::PUBLIC specifies that the command should be available via a
restricted RPC connection.
- rpc::BINARY specifies that the command is not JSON, but rather is
accessible as /name and takes and returns values in the magic epee
binary "portable storage" (lol) data format.
- rpc::LEGACY specifies that the command should be available via the
non-json-rpc interface at `/name` for backwards compatibility (in
addition to the JSON-RPC interface).
- some epee serialization got unwrapped and de-templatized so that it
can be moved into a .cpp file with just declarations in the .h. (This
makes a *huge* difference for core_rpc_server_commands_defs.h and for
every compilation unit that includes it which previously had to
compile all the serialization code and then throw all by one copy away
at link time). This required some new macros so as to not break a ton
of places that will use the old way putting everything in the headers;
The RPC code uses this as does a few other places; there are comments
in contrib/epee/include/serialization/keyvalue_serialization.h as to
how to use it.
- Detemplatized a bunch of epee/storages code. Most of it should have
have been using templates at all (because it can only ever be called
with one type!), and now it isn't. This broke some things that didn't
properly compile because of missing headers or (in one case) a messed
up circular dependency.
- Significantly simplified a bunch of over-templatized serialization
code.
- All RPC serialization definitions is now out of
core_rpc_server_commands_defs.h and into a single .cpp file
(core_rpc_server_commands_defs.cpp).
- core RPC no longer uses the disgusting
BEGIN_URI_MAP2/MAP_URI_BLAH_BLAH macros. This was a terrible design
that forced slamming tons of code into a common header that didn't
need to be there.
- epee::struct_init is gone. It was a horrible hack that instiated
multiple templates just so the coder could be so lazy and write
`some_type var;` instead of properly value initializing with
`some_type var{};`.
- Removed a bunch of useless crap from epee. In particular, forcing
extra template instantiations all over the place in order to nest
return objects inside JSON RPC values is no longer needed, as are a
bunch of stuff related to the above de-macroization of the code.
- get_all_service_nodes, get_service_nodes, and get_n_service_nodes are
now combined into a single `get_service_nodes` (with deprecated
aliases for the others), which eliminates a fair amount of
duplication. The biggest obstacle here was getting the requested
fields reference passed through: this is now done by a new ability to
stash a context in the serialization object that can be retrieved by a
sub-serialized type.
LMQ-specifics:
- The LokiMQ instance moves into `cryptonote::core` rather than being
inside cryptonote_protocol. Currently the instance is used both for
qnet and rpc calls (and so needs to be in a common place), but I also
intend future PRs to use the batching code for job processing
(replacing the current threaded job queue).
- rpc/lmq_server.h handles the actual LMQ-request-to-core-RPC glue.
Unlike http_server it isn't technically running the whole LMQ stack
from here, but the parallel name with http_server seemed appropriate.
- All RPC endpoints are supported by LMQ under the same names as defined
generically, but prefixed with `rpc.` for public commands and `admin.`
for restricted ones.
- service node keys are now always available, even when not running in
`--service-node` mode: this is because we want the x25519 key for
being able to offer CURVE encryption for lmq RPC end-points, and
because it doesn't hurt to have them available all the time. In the
RPC layer this is now called "get_service_keys" (with
"get_service_node_key" as an alias) since they aren't strictly only
for service nodes. This also means code needs to check
m_service_node, and not m_service_node_keys, to tell if it is running
as a service node. (This is also easier to notice because
m_service_node_keys got renamed to `m_service_keys`).
- Added block and mempool monitoring LMQ RPC endpoints: `sub.block` and
`sub.mempool` subscribes the connection for new block and new mempool
TX notifications. The latter can notify on just blink txes, or all
new mempool txes (but only new ones -- txes dumped from a block don't
trigger it). The client gets pushed a [`notify.block`, `height`,
`hash`] or [`notify.tx`, `txhash`, `blob`] message when something
arrives.
Minor details:
- rpc::version_t is now a {major,minor} pair. Forcing everyone to pack
and unpack a uint32_t was gross.
- Changed some macros to constexprs (e.g. CORE_RPC_ERROR_CODE_...).
(This immediately revealed a couple of bugs in the RPC code that was
assigning CORE_RPC_ERROR_CODE_... to a string, and it worked because
the macro allows implicit conversion to a char).
- De-templatizing useless templates in epee (i.e. a bunch of templated
types that were never invoked with different types) revealed a painful
circular dependency between epee and non-epee code for tor_address and
i2p_address. This crap is now handled in a suitably named
`net/epee_network_address_hack.cpp` hack because it really isn't
trivial to extricate this mess.
- Removed `epee/include/serialization/serialize_base.h`. Amazingly the
code somehow still all works perfectly with this previously vital
header removed.
- Removed bitrotted, unused epee "crypted_storage" and
"gzipped_inmemstorage" code.
- Replaced a bunch of epee::misc_utils::auto_scope_leave_caller with
LOKI_DEFERs. The epee version involves quite a bit more instantiation
and is ugly as sin. Also made the `loki::defer` class invokable for
some edge cases that need calling before destruction in particular
conditions.
- Moved the systemd code around; it makes much more sense to do the
systemd started notification as in daemon.cpp as late as possible
rather than in core (when we can still have startup failures, e.g. if
the RPC layer can't start).
- Made the systemd short status string available in the get_info RPC
(and no longer require building with systemd).
- during startup, print (only) the x25519 when not in SN mode, and
continue to print all three when in SN mode.
- DRYed out some RPC implementation code (such as set_limit)
- Made wallet_rpc stop using a raw m_wallet pointer
2020-04-28 01:25:43 +02:00
|
|
|
struct config
|
2019-04-09 10:07:13 +02:00
|
|
|
{
|
RPC overhaul
High-level details:
This redesigns the RPC layer to make it much easier to work with,
decouples it from an embedded HTTP server, and gets the vast majority of
the RPC serialization and dispatch code out of a very commonly included
header.
There is unfortunately rather a lot of interconnected code here that
cannot be easily separated out into separate commits. The full details
of what happens here are as follows:
Major details:
- All of the RPC code is now in a `cryptonote::rpc` namespace; this
renames quite a bit to be less verbose: e.g. CORE_RPC_STATUS_OK
becomes `rpc::STATUS_OK`, and `cryptonote::COMMAND_RPC_SOME_LONG_NAME`
becomes `rpc::SOME_LONG_NAME` (or just SOME_LONG_NAME for code already
working in the `rpc` namespace).
- `core_rpc_server` is now completely decoupled from providing any
request protocol: it is now *just* the core RPC call handler.
- The HTTP RPC interface now lives in a new rpc/http_server.h; this code
handles listening for HTTP requests and dispatching them to
core_rpc_server, then sending the results back to the caller.
- There is similarly a rpc/lmq_server.h for LMQ RPC code; more details
on this (and other LMQ specifics) below.
- RPC implementing code now returns the response object and throws when
things go wrong which simplifies much of the rpc error handling. They
can throw anything; generic exceptions get logged and a generic
"internal error" message gets returned to the caller, but there is
also an `rpc_error` class to return an error code and message used by
some json-rpc commands.
- RPC implementing functions now overload `core_rpc_server::invoke`
following the pattern:
RPC_BLAH_BLAH::response core_rpc_server::invoke(RPC_BLAH_BLAH::request&& req, rpc_context context);
This overloading makes the code vastly simpler: all instantiations are
now done with a small amount of generic instantiation code in a single
.cpp rather than needing to go to hell and back with a nest of epee
macros in a core header.
- each RPC endpoint is now defined by the RPC types themselves,
including its accessible names and permissions, in
core_rpc_server_commands_defs.h:
- every RPC structure now has a static `names()` function that returns
the names by which the end point is accessible. (The first one is
the primary, the others are for deprecated aliases).
- RPC command wrappers define their permissions and type by inheriting
from special tag classes:
- rpc::RPC_COMMAND is a basic, admin-only, JSON command, available
via JSON RPC. *All* JSON commands are now available via JSON RPC,
instead of the previous mix of some being at /foo and others at
/json_rpc. (Ones that were previously at /foo are still there for
backwards compatibility; see `rpc::LEGACY` below).
- rpc::PUBLIC specifies that the command should be available via a
restricted RPC connection.
- rpc::BINARY specifies that the command is not JSON, but rather is
accessible as /name and takes and returns values in the magic epee
binary "portable storage" (lol) data format.
- rpc::LEGACY specifies that the command should be available via the
non-json-rpc interface at `/name` for backwards compatibility (in
addition to the JSON-RPC interface).
- some epee serialization got unwrapped and de-templatized so that it
can be moved into a .cpp file with just declarations in the .h. (This
makes a *huge* difference for core_rpc_server_commands_defs.h and for
every compilation unit that includes it which previously had to
compile all the serialization code and then throw all by one copy away
at link time). This required some new macros so as to not break a ton
of places that will use the old way putting everything in the headers;
The RPC code uses this as does a few other places; there are comments
in contrib/epee/include/serialization/keyvalue_serialization.h as to
how to use it.
- Detemplatized a bunch of epee/storages code. Most of it should have
have been using templates at all (because it can only ever be called
with one type!), and now it isn't. This broke some things that didn't
properly compile because of missing headers or (in one case) a messed
up circular dependency.
- Significantly simplified a bunch of over-templatized serialization
code.
- All RPC serialization definitions is now out of
core_rpc_server_commands_defs.h and into a single .cpp file
(core_rpc_server_commands_defs.cpp).
- core RPC no longer uses the disgusting
BEGIN_URI_MAP2/MAP_URI_BLAH_BLAH macros. This was a terrible design
that forced slamming tons of code into a common header that didn't
need to be there.
- epee::struct_init is gone. It was a horrible hack that instiated
multiple templates just so the coder could be so lazy and write
`some_type var;` instead of properly value initializing with
`some_type var{};`.
- Removed a bunch of useless crap from epee. In particular, forcing
extra template instantiations all over the place in order to nest
return objects inside JSON RPC values is no longer needed, as are a
bunch of stuff related to the above de-macroization of the code.
- get_all_service_nodes, get_service_nodes, and get_n_service_nodes are
now combined into a single `get_service_nodes` (with deprecated
aliases for the others), which eliminates a fair amount of
duplication. The biggest obstacle here was getting the requested
fields reference passed through: this is now done by a new ability to
stash a context in the serialization object that can be retrieved by a
sub-serialized type.
LMQ-specifics:
- The LokiMQ instance moves into `cryptonote::core` rather than being
inside cryptonote_protocol. Currently the instance is used both for
qnet and rpc calls (and so needs to be in a common place), but I also
intend future PRs to use the batching code for job processing
(replacing the current threaded job queue).
- rpc/lmq_server.h handles the actual LMQ-request-to-core-RPC glue.
Unlike http_server it isn't technically running the whole LMQ stack
from here, but the parallel name with http_server seemed appropriate.
- All RPC endpoints are supported by LMQ under the same names as defined
generically, but prefixed with `rpc.` for public commands and `admin.`
for restricted ones.
- service node keys are now always available, even when not running in
`--service-node` mode: this is because we want the x25519 key for
being able to offer CURVE encryption for lmq RPC end-points, and
because it doesn't hurt to have them available all the time. In the
RPC layer this is now called "get_service_keys" (with
"get_service_node_key" as an alias) since they aren't strictly only
for service nodes. This also means code needs to check
m_service_node, and not m_service_node_keys, to tell if it is running
as a service node. (This is also easier to notice because
m_service_node_keys got renamed to `m_service_keys`).
- Added block and mempool monitoring LMQ RPC endpoints: `sub.block` and
`sub.mempool` subscribes the connection for new block and new mempool
TX notifications. The latter can notify on just blink txes, or all
new mempool txes (but only new ones -- txes dumped from a block don't
trigger it). The client gets pushed a [`notify.block`, `height`,
`hash`] or [`notify.tx`, `txhash`, `blob`] message when something
arrives.
Minor details:
- rpc::version_t is now a {major,minor} pair. Forcing everyone to pack
and unpack a uint32_t was gross.
- Changed some macros to constexprs (e.g. CORE_RPC_ERROR_CODE_...).
(This immediately revealed a couple of bugs in the RPC code that was
assigning CORE_RPC_ERROR_CODE_... to a string, and it worked because
the macro allows implicit conversion to a char).
- De-templatizing useless templates in epee (i.e. a bunch of templated
types that were never invoked with different types) revealed a painful
circular dependency between epee and non-epee code for tor_address and
i2p_address. This crap is now handled in a suitably named
`net/epee_network_address_hack.cpp` hack because it really isn't
trivial to extricate this mess.
- Removed `epee/include/serialization/serialize_base.h`. Amazingly the
code somehow still all works perfectly with this previously vital
header removed.
- Removed bitrotted, unused epee "crypted_storage" and
"gzipped_inmemstorage" code.
- Replaced a bunch of epee::misc_utils::auto_scope_leave_caller with
LOKI_DEFERs. The epee version involves quite a bit more instantiation
and is ugly as sin. Also made the `loki::defer` class invokable for
some edge cases that need calling before destruction in particular
conditions.
- Moved the systemd code around; it makes much more sense to do the
systemd started notification as in daemon.cpp as late as possible
rather than in core (when we can still have startup failures, e.g. if
the RPC layer can't start).
- Made the systemd short status string available in the get_info RPC
(and no longer require building with systemd).
- during startup, print (only) the x25519 when not in SN mode, and
continue to print all three when in SN mode.
- DRYed out some RPC implementation code (such as set_limit)
- Made wallet_rpc stop using a raw m_wallet pointer
2020-04-28 01:25:43 +02:00
|
|
|
network_config m_net_config{};
|
|
|
|
uint64_t m_peer_id{crypto::rand<uint64_t>()};
|
|
|
|
uint32_t m_support_flags{0};
|
2019-04-09 10:07:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct network_zone
|
|
|
|
{
|
|
|
|
network_zone()
|
|
|
|
: m_connect(nullptr),
|
|
|
|
m_net_server(epee::net_utils::e_connection_type_P2P),
|
|
|
|
m_bind_ip(),
|
2019-04-11 00:34:30 +02:00
|
|
|
m_bind_ipv6_address(),
|
2019-04-09 10:07:13 +02:00
|
|
|
m_port(),
|
2019-04-11 00:34:30 +02:00
|
|
|
m_port_ipv6(),
|
2019-05-16 22:34:22 +02:00
|
|
|
m_notifier(),
|
2019-04-09 10:07:13 +02:00
|
|
|
m_our_address(),
|
|
|
|
m_peerlist(),
|
|
|
|
m_config{},
|
|
|
|
m_proxy_address(),
|
|
|
|
m_current_number_of_out_peers(0),
|
|
|
|
m_current_number_of_in_peers(0),
|
|
|
|
m_can_pingback(false)
|
|
|
|
{
|
|
|
|
set_config_defaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
network_zone(boost::asio::io_service& public_service)
|
|
|
|
: m_connect(nullptr),
|
|
|
|
m_net_server(public_service, epee::net_utils::e_connection_type_P2P),
|
|
|
|
m_bind_ip(),
|
2019-04-11 00:34:30 +02:00
|
|
|
m_bind_ipv6_address(),
|
2019-04-09 10:07:13 +02:00
|
|
|
m_port(),
|
2019-04-11 00:34:30 +02:00
|
|
|
m_port_ipv6(),
|
2019-05-16 22:34:22 +02:00
|
|
|
m_notifier(),
|
2019-04-09 10:07:13 +02:00
|
|
|
m_our_address(),
|
|
|
|
m_peerlist(),
|
|
|
|
m_config{},
|
|
|
|
m_proxy_address(),
|
|
|
|
m_current_number_of_out_peers(0),
|
|
|
|
m_current_number_of_in_peers(0),
|
|
|
|
m_can_pingback(false)
|
|
|
|
{
|
|
|
|
set_config_defaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
connect_func* m_connect;
|
|
|
|
net_server m_net_server;
|
|
|
|
std::string m_bind_ip;
|
2019-04-11 00:34:30 +02:00
|
|
|
std::string m_bind_ipv6_address;
|
2019-04-09 10:07:13 +02:00
|
|
|
std::string m_port;
|
2019-04-11 00:34:30 +02:00
|
|
|
std::string m_port_ipv6;
|
2019-05-16 22:34:22 +02:00
|
|
|
cryptonote::levin::notify m_notifier;
|
2019-04-09 10:07:13 +02:00
|
|
|
epee::net_utils::network_address m_our_address; // in anonymity networks
|
|
|
|
peerlist_manager m_peerlist;
|
|
|
|
config m_config;
|
|
|
|
boost::asio::ip::tcp::endpoint m_proxy_address;
|
|
|
|
std::atomic<unsigned int> m_current_number_of_out_peers;
|
|
|
|
std::atomic<unsigned int> m_current_number_of_in_peers;
|
|
|
|
bool m_can_pingback;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void set_config_defaults() noexcept
|
|
|
|
{
|
|
|
|
// at this moment we have a hardcoded config
|
|
|
|
m_config.m_net_config.handshake_interval = P2P_DEFAULT_HANDSHAKE_INTERVAL;
|
|
|
|
m_config.m_net_config.packet_max_size = P2P_DEFAULT_PACKET_MAX_SIZE;
|
|
|
|
m_config.m_net_config.config_id = 0;
|
|
|
|
m_config.m_net_config.connection_timeout = P2P_DEFAULT_CONNECTION_TIMEOUT;
|
|
|
|
m_config.m_net_config.ping_connection_timeout = P2P_DEFAULT_PING_CONNECTION_TIMEOUT;
|
|
|
|
m_config.m_net_config.send_peerlist_sz = P2P_DEFAULT_PEERS_IN_HANDSHAKE;
|
|
|
|
m_config.m_support_flags = 0; // only set in public zone
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-06 12:28:02 +02:00
|
|
|
enum igd_t
|
|
|
|
{
|
|
|
|
no_igd,
|
|
|
|
igd,
|
|
|
|
delayed_igd,
|
|
|
|
};
|
|
|
|
|
2014-03-03 23:07:58 +01:00
|
|
|
public:
|
|
|
|
typedef t_payload_net_handler payload_net_handler;
|
2014-09-08 19:40:28 +02:00
|
|
|
|
2015-04-01 19:00:45 +02:00
|
|
|
node_server(t_payload_net_handler& payload_handler)
|
2019-04-09 10:07:13 +02:00
|
|
|
: m_payload_handler(payload_handler),
|
|
|
|
m_external_port(0),
|
2019-02-24 09:47:49 +01:00
|
|
|
m_rpc_port(0),
|
2019-04-09 10:07:13 +02:00
|
|
|
m_allow_local_ip(false),
|
|
|
|
m_hide_my_port(false),
|
2019-06-06 12:28:02 +02:00
|
|
|
m_igd(no_igd),
|
2019-04-09 10:07:13 +02:00
|
|
|
m_offline(false),
|
|
|
|
is_closing(false),
|
|
|
|
m_network_id()
|
2015-04-20 19:17:11 +02:00
|
|
|
{}
|
2019-04-09 10:07:13 +02:00
|
|
|
virtual ~node_server();
|
2014-03-03 23:07:58 +01:00
|
|
|
|
|
|
|
static void init_options(boost::program_options::options_description& desc);
|
|
|
|
|
|
|
|
bool run();
|
2019-04-09 10:07:13 +02:00
|
|
|
network_zone& add_zone(epee::net_utils::zone zone);
|
2015-01-29 23:10:53 +01:00
|
|
|
bool init(const boost::program_options::variables_map& vm);
|
2014-03-03 23:07:58 +01:00
|
|
|
bool deinit();
|
|
|
|
bool send_stop_signal();
|
2017-09-01 09:50:22 +02:00
|
|
|
uint32_t get_this_peer_port(){return m_listening_port;}
|
2014-03-03 23:07:58 +01:00
|
|
|
t_payload_net_handler& get_payload_object();
|
|
|
|
|
|
|
|
// debug functions
|
|
|
|
bool log_peerlist();
|
|
|
|
bool log_connections();
|
2019-04-09 10:07:13 +02:00
|
|
|
|
|
|
|
// These functions only return information for the "public" zone
|
|
|
|
virtual uint64_t get_public_connections_count();
|
|
|
|
size_t get_public_outgoing_connections_count();
|
|
|
|
size_t get_public_white_peers_count();
|
|
|
|
size_t get_public_gray_peers_count();
|
|
|
|
void get_public_peerlist(std::vector<peerlist_entry>& gray, std::vector<peerlist_entry>& white);
|
2019-06-26 11:14:23 +02:00
|
|
|
void get_peerlist(std::vector<peerlist_entry>& gray, std::vector<peerlist_entry>& white);
|
2019-04-09 10:07:13 +02:00
|
|
|
|
|
|
|
void change_max_out_public_peers(size_t count);
|
2019-05-28 19:54:41 +02:00
|
|
|
uint32_t get_max_out_public_peers() const;
|
2019-04-09 10:07:13 +02:00
|
|
|
void change_max_in_public_peers(size_t count);
|
2019-05-28 19:54:41 +02:00
|
|
|
uint32_t get_max_in_public_peers() const;
|
2017-05-27 12:35:54 +02:00
|
|
|
virtual bool block_host(const epee::net_utils::network_address &adress, time_t seconds = P2P_IP_BLOCKTIME);
|
|
|
|
virtual bool unblock_host(const epee::net_utils::network_address &address);
|
2019-03-29 11:47:53 +01:00
|
|
|
virtual bool block_subnet(const epee::net_utils::ipv4_network_subnet &subnet, time_t seconds = P2P_IP_BLOCKTIME);
|
|
|
|
virtual bool unblock_subnet(const epee::net_utils::ipv4_network_subnet &subnet);
|
Purge epee::critical_crap and CRITICAL_CRAP
This purges epee::critical_region/epee::critical_section and the awful
CRITICAL_REGION_LOCAL and CRITICAL_REGION_LOCAL1 and
CRITICAL_REGION_BEGIN1 and all that crap from epee code.
This wrapper class around a mutex is just painful, macro-infested
indirection that accomplishes nothing (and, worse, forces all using code
to use a std::recursive_mutex even when a different mutex type is more
appropriate).
This commit purges it, replacing the "critical_section" mutex wrappers
with either std::mutex, std::recursive_mutex, or std::shared_mutex as
appropriate. I kept anything that looked uncertain as a
recursive_mutex, simple cases that obviously don't recurse as
std::mutex, and simple cases with reader/writing mechanics as a
shared_mutex.
Ideally all the recursive_mutexes should be eliminated because a
recursive_mutex is almost always a design flaw where someone has let the
locking code get impossibly tangled, but that requires a lot more time
to properly trace down all the ways the mutexes are used.
Other notable changes:
- There was one NIH promise/future-like class here that was used in
example one place in p2p/net_node; I replaced it with a
std::promise/future.
- moved the mutex for LMDB resizing into LMDB itself; having it in the
abstract base class is bad design, and also made it impossible to make a
moveable base class (which gets used for the fake db classes in the test
code).
2020-06-22 21:40:31 +02:00
|
|
|
virtual bool is_host_blocked(const epee::net_utils::network_address &address, time_t *seconds) { return !is_remote_host_allowed(address, seconds); }
|
|
|
|
virtual std::map<std::string, time_t> get_blocked_hosts() { std::shared_lock lock{m_blocked_hosts_lock}; return m_blocked_hosts; }
|
|
|
|
virtual std::map<epee::net_utils::ipv4_network_subnet, time_t> get_blocked_subnets() { std::shared_lock lock{m_blocked_hosts_lock}; return m_blocked_subnets; }
|
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-30 00:30:51 +02:00
|
|
|
|
|
|
|
virtual void add_used_stripe_peer(const typename t_payload_net_handler::connection_context &context);
|
|
|
|
virtual void remove_used_stripe_peer(const typename t_payload_net_handler::connection_context &context);
|
|
|
|
virtual void clear_used_stripe_peers();
|
|
|
|
|
2014-03-03 23:07:58 +01:00
|
|
|
private:
|
2014-09-17 21:35:52 +02:00
|
|
|
const std::vector<std::string> m_seed_nodes_list =
|
2018-08-08 06:44:38 +02:00
|
|
|
{
|
|
|
|
// TODO(loki): "seeds.loki.network"
|
2014-09-17 21:35:52 +02:00
|
|
|
};
|
2015-12-14 05:54:39 +01:00
|
|
|
|
2015-01-05 20:30:17 +01:00
|
|
|
bool islimitup=false;
|
|
|
|
bool islimitdown=false;
|
2014-09-17 21:35:52 +02:00
|
|
|
|
2014-03-03 23:07:58 +01:00
|
|
|
CHAIN_LEVIN_INVOKE_MAP2(p2p_connection_context); //move levin_commands_handler interface invoke(...) callbacks into invoke map
|
|
|
|
CHAIN_LEVIN_NOTIFY_MAP2(p2p_connection_context); //move levin_commands_handler interface notify(...) callbacks into nothing
|
|
|
|
|
|
|
|
BEGIN_INVOKE_MAP2(node_server)
|
2019-04-09 10:07:13 +02:00
|
|
|
if (is_filtered_command(context.m_remote_address, command))
|
|
|
|
return LEVIN_ERROR_CONNECTION_HANDLER_NOT_DEFINED;
|
|
|
|
|
2020-06-02 01:36:30 +02:00
|
|
|
HANDLE_INVOKE_T2(COMMAND_HANDSHAKE, handle_handshake)
|
|
|
|
HANDLE_INVOKE_T2(COMMAND_TIMED_SYNC, handle_timed_sync)
|
|
|
|
HANDLE_INVOKE_T2(COMMAND_PING, handle_ping)
|
|
|
|
HANDLE_INVOKE_T2(COMMAND_REQUEST_SUPPORT_FLAGS, handle_get_support_flags)
|
2014-03-03 23:07:58 +01:00
|
|
|
CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT(m_payload_handler, typename t_payload_net_handler::connection_context&)
|
|
|
|
END_INVOKE_MAP2()
|
|
|
|
|
2017-02-09 01:11:58 +01:00
|
|
|
enum PeerType { anchor = 0, white, gray };
|
|
|
|
|
2014-03-03 23:07:58 +01:00
|
|
|
//----------------- commands handlers ----------------------------------------------
|
|
|
|
int handle_handshake(int command, typename COMMAND_HANDSHAKE::request& arg, typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context);
|
|
|
|
int handle_timed_sync(int command, typename COMMAND_TIMED_SYNC::request& arg, typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context);
|
|
|
|
int handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, p2p_connection_context& context);
|
2016-10-26 21:00:08 +02:00
|
|
|
int handle_get_support_flags(int command, COMMAND_REQUEST_SUPPORT_FLAGS::request& arg, COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context);
|
2014-03-03 23:07:58 +01:00
|
|
|
bool init_config();
|
2017-01-22 12:37:55 +01:00
|
|
|
bool make_default_peer_id();
|
2014-03-03 23:07:58 +01:00
|
|
|
bool make_default_config();
|
|
|
|
bool store_config();
|
|
|
|
|
|
|
|
|
|
|
|
//----------------- levin_commands_handler -------------------------------------------------------------
|
|
|
|
virtual void on_connection_new(p2p_connection_context& context);
|
|
|
|
virtual void on_connection_close(p2p_connection_context& context);
|
|
|
|
virtual void callback(p2p_connection_context& context);
|
|
|
|
//----------------- i_p2p_endpoint -------------------------------------------------------------
|
2019-04-09 10:07:13 +02:00
|
|
|
virtual bool relay_notify_to_list(int command, const epee::span<const uint8_t> data_buff, std::vector<std::pair<epee::net_utils::zone, boost::uuids::uuid>> connections);
|
2019-05-16 22:34:22 +02:00
|
|
|
virtual epee::net_utils::zone send_txs(std::vector<cryptonote::blobdata> txs, const epee::net_utils::zone origin, const boost::uuids::uuid& source, const bool pad_txs);
|
2018-12-06 19:04:33 +01:00
|
|
|
virtual bool invoke_command_to_peer(int command, const epee::span<const uint8_t> req_buff, std::string& resp_buff, const epee::net_utils::connection_context_base& context);
|
|
|
|
virtual bool invoke_notify_to_peer(int command, const epee::span<const uint8_t> req_buff, const epee::net_utils::connection_context_base& context);
|
2014-03-03 23:07:58 +01:00
|
|
|
virtual bool drop_connection(const epee::net_utils::connection_context_base& context);
|
|
|
|
virtual void request_callback(const epee::net_utils::connection_context_base& context);
|
2016-10-26 21:00:08 +02:00
|
|
|
virtual void for_each_connection(std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
|
2017-07-02 23:41:15 +02:00
|
|
|
virtual bool for_connection(const boost::uuids::uuid&, std::function<bool(typename t_payload_net_handler::connection_context&, peerid_type, uint32_t)> f);
|
2017-05-27 12:35:54 +02:00
|
|
|
virtual bool add_host_fail(const epee::net_utils::network_address &address);
|
2015-11-23 18:34:55 +01:00
|
|
|
//----------------- i_connection_filter --------------------------------------------------------
|
2019-03-29 11:47:53 +01:00
|
|
|
virtual bool is_remote_host_allowed(const epee::net_utils::network_address &address, time_t *t = NULL);
|
2014-03-03 23:07:58 +01:00
|
|
|
//-----------------------------------------------------------------------------------------------
|
2017-05-27 12:35:54 +02:00
|
|
|
bool parse_peer_from_string(epee::net_utils::network_address& pe, const std::string& node_addr, uint16_t default_port = 0);
|
2014-09-08 18:51:04 +02:00
|
|
|
bool handle_command_line(
|
|
|
|
const boost::program_options::variables_map& vm
|
|
|
|
);
|
2014-03-03 23:07:58 +01:00
|
|
|
bool idle_worker();
|
2019-12-04 13:51:45 +01:00
|
|
|
bool handle_remote_peerlist(const std::vector<peerlist_entry>& peerlist, const epee::net_utils::connection_context_base& context);
|
2019-04-09 10:07:13 +02:00
|
|
|
bool get_local_node_data(basic_node_data& node_data, const network_zone& zone);
|
2014-03-03 23:07:58 +01:00
|
|
|
//bool get_local_handshake_data(handshake_data& hshd);
|
|
|
|
|
2019-06-19 00:11:18 +02:00
|
|
|
bool sanitize_peerlist(std::vector<peerlist_entry>& local_peerlist);
|
2014-03-03 23:07:58 +01:00
|
|
|
|
|
|
|
bool connections_maker();
|
|
|
|
bool peer_sync_idle_maker();
|
|
|
|
bool do_handshake_with_peer(peerid_type& pi, p2p_connection_context& context, bool just_take_peerlist = false);
|
2014-05-25 19:06:40 +02:00
|
|
|
bool do_peer_timed_sync(const epee::net_utils::connection_context_base& context, peerid_type peer_id);
|
2014-03-03 23:07:58 +01:00
|
|
|
|
2017-02-09 01:11:58 +01:00
|
|
|
bool make_new_connection_from_anchor_peerlist(const std::vector<anchor_peerlist_entry>& anchor_peerlist);
|
2019-04-09 10:07:13 +02:00
|
|
|
bool make_new_connection_from_peerlist(network_zone& zone, bool use_white_list);
|
2017-05-27 12:35:54 +02:00
|
|
|
bool try_to_connect_and_handshake_with_new_peer(const epee::net_utils::network_address& na, bool just_take_peerlist = false, uint64_t last_seen_stamp = 0, PeerType peer_type = white, uint64_t first_seen_stamp = 0);
|
2014-03-03 23:07:58 +01:00
|
|
|
size_t get_random_index_with_fixed_probability(size_t max_index);
|
|
|
|
bool is_peer_used(const peerlist_entry& peer);
|
2017-02-09 01:11:58 +01:00
|
|
|
bool is_peer_used(const anchor_peerlist_entry& peer);
|
2017-05-27 12:35:54 +02:00
|
|
|
bool is_addr_connected(const epee::net_utils::network_address& peer);
|
2019-04-11 00:34:30 +02:00
|
|
|
void add_upnp_port_mapping_impl(uint32_t port, bool ipv6=false);
|
|
|
|
void add_upnp_port_mapping_v4(uint32_t port);
|
|
|
|
void add_upnp_port_mapping_v6(uint32_t port);
|
|
|
|
void add_upnp_port_mapping(uint32_t port, bool ipv4=true, bool ipv6=false);
|
|
|
|
void delete_upnp_port_mapping_impl(uint32_t port, bool ipv6=false);
|
|
|
|
void delete_upnp_port_mapping_v4(uint32_t port);
|
|
|
|
void delete_upnp_port_mapping_v6(uint32_t port);
|
2017-08-29 23:28:23 +02:00
|
|
|
void delete_upnp_port_mapping(uint32_t port);
|
2014-03-03 23:07:58 +01:00
|
|
|
template<class t_callback>
|
2018-02-02 19:45:12 +01:00
|
|
|
bool try_ping(basic_node_data& node_data, p2p_connection_context& context, const t_callback &cb);
|
2016-10-26 21:00:08 +02:00
|
|
|
bool try_get_support_flags(const p2p_connection_context& context, std::function<void(p2p_connection_context&, const uint32_t&)> f);
|
2019-04-09 10:07:13 +02:00
|
|
|
bool make_expected_connections_count(network_zone& zone, PeerType peer_type, size_t expected_connections);
|
2020-01-15 15:42:52 +01:00
|
|
|
void record_addr_failed(const epee::net_utils::network_address& addr);
|
2017-05-27 12:35:54 +02:00
|
|
|
bool is_addr_recently_failed(const epee::net_utils::network_address& addr);
|
|
|
|
bool is_priority_node(const epee::net_utils::network_address& na);
|
2018-02-16 12:04:04 +01:00
|
|
|
std::set<std::string> get_seed_nodes(cryptonote::network_type nettype) const;
|
2020-04-10 04:24:00 +02:00
|
|
|
std::set<std::string> get_seed_nodes();
|
2017-08-09 23:44:39 +02:00
|
|
|
bool connect_to_seed();
|
2014-05-25 19:06:40 +02:00
|
|
|
|
|
|
|
template <class Container>
|
|
|
|
bool connect_to_peerlist(const Container& peers);
|
|
|
|
|
|
|
|
template <class Container>
|
|
|
|
bool parse_peers_and_add_to_container(const boost::program_options::variables_map& vm, const command_line::arg_descriptor<std::vector<std::string> > & arg, Container& container);
|
2014-03-03 23:07:58 +01:00
|
|
|
|
2019-04-09 10:07:13 +02:00
|
|
|
bool set_max_out_peers(network_zone& zone, int64_t max);
|
|
|
|
bool set_max_in_peers(network_zone& zone, int64_t max);
|
2015-12-14 05:54:39 +01:00
|
|
|
bool set_tos_flag(const boost::program_options::variables_map& vm, int limit);
|
|
|
|
|
|
|
|
bool set_rate_up_limit(const boost::program_options::variables_map& vm, int64_t limit);
|
|
|
|
bool set_rate_down_limit(const boost::program_options::variables_map& vm, int64_t limit);
|
|
|
|
bool set_rate_limit(const boost::program_options::variables_map& vm, int64_t limit);
|
2015-01-05 20:30:17 +01:00
|
|
|
|
2017-05-27 12:35:54 +02:00
|
|
|
bool has_too_many_connections(const epee::net_utils::network_address &address);
|
2019-04-09 10:07:13 +02:00
|
|
|
size_t get_incoming_connections_count();
|
|
|
|
size_t get_incoming_connections_count(network_zone&);
|
|
|
|
size_t get_outgoing_connections_count();
|
|
|
|
size_t get_outgoing_connections_count(network_zone&);
|
2017-01-14 13:21:20 +01:00
|
|
|
|
2017-05-27 12:35:54 +02:00
|
|
|
bool check_connection_and_handshake_with_peer(const epee::net_utils::network_address& na, uint64_t last_seen_stamp);
|
2017-01-21 00:59:04 +01:00
|
|
|
bool gray_peerlist_housekeeping();
|
2018-05-25 13:34:52 +02:00
|
|
|
bool check_incoming_connections();
|
2017-01-21 00:59:04 +01:00
|
|
|
|
2015-02-24 21:02:48 +01:00
|
|
|
void kill() { ///< will be called e.g. from deinit()
|
2020-06-02 20:37:36 +02:00
|
|
|
MINFO("Killing the net_node");
|
2015-12-14 05:54:39 +01:00
|
|
|
is_closing = true;
|
2020-06-03 04:51:35 +02:00
|
|
|
if(mPeersLoggerThread)
|
2015-12-14 05:54:39 +01:00
|
|
|
mPeersLoggerThread->join(); // make sure the thread finishes
|
2020-06-02 20:37:36 +02:00
|
|
|
MINFO("Joined extra background net_node threads");
|
2015-12-14 05:54:39 +01:00
|
|
|
}
|
2015-02-24 21:02:48 +01:00
|
|
|
|
2014-03-03 23:07:58 +01:00
|
|
|
//debug functions
|
|
|
|
std::string print_connections_container();
|
|
|
|
|
|
|
|
|
2015-12-14 05:54:39 +01:00
|
|
|
public:
|
2015-04-01 19:00:45 +02:00
|
|
|
|
2019-02-24 09:47:49 +01:00
|
|
|
void set_rpc_port(uint16_t rpc_port)
|
|
|
|
{
|
|
|
|
m_rpc_port = rpc_port;
|
|
|
|
}
|
|
|
|
|
2019-12-26 07:43:47 +01:00
|
|
|
void reset_peer_handshake_timer()
|
|
|
|
{
|
|
|
|
m_peer_handshake_idle_maker_interval.reset();
|
|
|
|
}
|
|
|
|
|
2015-12-14 05:54:39 +01:00
|
|
|
private:
|
2014-03-03 23:07:58 +01:00
|
|
|
std::string m_config_folder;
|
|
|
|
|
|
|
|
bool m_have_address;
|
|
|
|
bool m_first_connection_maker_call;
|
2017-09-01 09:50:22 +02:00
|
|
|
uint32_t m_listening_port;
|
2019-04-11 00:34:30 +02:00
|
|
|
uint32_t m_listening_port_ipv6;
|
2014-03-03 23:07:58 +01:00
|
|
|
uint32_t m_external_port;
|
2019-02-24 09:47:49 +01:00
|
|
|
uint16_t m_rpc_port;
|
2014-03-03 23:07:58 +01:00
|
|
|
bool m_allow_local_ip;
|
|
|
|
bool m_hide_my_port;
|
2019-06-06 12:28:02 +02:00
|
|
|
igd_t m_igd;
|
2015-12-07 21:21:45 +01:00
|
|
|
bool m_offline;
|
2019-04-11 00:34:30 +02:00
|
|
|
bool m_use_ipv6;
|
|
|
|
bool m_require_ipv4;
|
2015-02-24 21:02:48 +01:00
|
|
|
std::atomic<bool> is_closing;
|
2020-06-03 04:51:35 +02:00
|
|
|
std::optional<std::thread> mPeersLoggerThread;
|
2014-03-03 23:07:58 +01:00
|
|
|
|
|
|
|
t_payload_net_handler& m_payload_handler;
|
2019-04-09 10:07:13 +02:00
|
|
|
peerlist_storage m_peerlist_storage;
|
2014-03-03 23:07:58 +01:00
|
|
|
|
2020-05-26 07:15:25 +02:00
|
|
|
tools::periodic_task m_peer_handshake_idle_maker_interval{std::chrono::seconds{P2P_DEFAULT_HANDSHAKE_INTERVAL}};
|
|
|
|
tools::periodic_task m_connections_maker_interval{1s};
|
|
|
|
tools::periodic_task m_peerlist_store_interval{30min};
|
|
|
|
tools::periodic_task m_gray_peerlist_housekeeping_interval{1min};
|
|
|
|
tools::periodic_task m_incoming_connections_interval{1h};
|
2014-03-03 23:07:58 +01:00
|
|
|
|
2017-05-27 12:35:54 +02:00
|
|
|
std::list<epee::net_utils::network_address> m_priority_peers;
|
|
|
|
std::vector<epee::net_utils::network_address> m_exclusive_peers;
|
|
|
|
std::vector<epee::net_utils::network_address> m_seed_nodes;
|
2020-06-22 02:42:23 +02:00
|
|
|
std::atomic<bool> m_seed_nodes_initialized{false};
|
|
|
|
std::shared_mutex m_seed_nodes_mutex;
|
2020-04-10 04:24:00 +02:00
|
|
|
std::atomic_flag m_fallback_seed_nodes_added;
|
2019-04-09 10:07:13 +02:00
|
|
|
std::vector<nodetool::peerlist_entry> m_command_line_peers;
|
2014-03-03 23:07:58 +01:00
|
|
|
uint64_t m_peer_livetime;
|
|
|
|
//keep connections to initiate some interactions
|
2019-04-09 10:07:13 +02:00
|
|
|
|
|
|
|
|
Replace epee http client with curl-based client
In short: epee's http client is garbage, standard violating, and
unreliable.
This completely removes the epee http client support and replaces it
with cpr, a curl-based C++ wrapper. rpc/http_client.h wraps cpr for RPC
requests specifically, but it is also usable directly.
This replacement has a number of advantages:
- requests are considerably more reliable. The epee http client code
assumes that a connection will be kept alive forever, and returns a
failure if a connection is ever closed. This results in some very
annoying things: for example, preparing a transaction and then waiting
a long tim before confirming it will usually result in an error
communication with the daemon. This is just terribly behaviour: the
right thing to do on a connection failure is to resubmit the request.
- epee's http client is broken in lots of other ways: for example, it
tries throwing SSL at the port to see if it is HTTPS, but this is
protocol violating and just breaks (with a several second timeout) on
anything that *isn't* epee http server (for example, when lokid is
behind a proxying server).
- even when it isn't doing the above, the client breaks in other ways:
for example, there is a comment (replaced in this PR) in the Trezor PR
code that forces a connection close after every request because epee's
http client doesn't do proper keep-alive request handling.
- it seems noticeably faster to me in practical use in this PR; both
simple requests (for example, when running `lokid status`) and
wallet<->daemon connections are faster, probably because of crappy
code in epee. (I think this is also related to the throw-ssl-at-it
junk above: the epee client always generates an ssl certificate during
static initialization because it might need one at some point).
- significantly reduces the amount of code we have to maintain.
- removes all the epee ssl option code: curl can handle all of that just
fine.
- removes the epee socks proxy code; curl can handle that just fine.
(And can do more: it also supports using HTTP/HTTPS proxies).
- When a cli wallet connection fails we know show why it failed (which
now is an error message from curl), which could have all sorts of
reasons like hostname resolution failure, bad ssl certificate, etc.
Previously you just got a useless generic error that tells you
nothing.
Other related changes in this PR:
- Drops the check-for-update and download-update code. To the best of
my knowledge these have never been supported in loki-core and so it
didn't seem worth the trouble to convert them to use cpr for the
requests.
- Cleaned up node_rpc_proxy return values: there was an inconsistent mix
of ways to return errors and how the returned strings were handled.
Instead this cleans it up to return a pair<bool, val>, which (with
C++17) can be transparently captured as:
auto [success, val] = node.whatever(req);
This drops the failure message string, but it was almost always set to
something fairly useless (if we want to resurrect it we could easily
change the first element to be a custom type with a bool operator for
success, and a `.error` attribute containing some error string, but
for the most part the current code wasn't doing much useful with the
failure string).
- changed local detection (for automatic trusted daemon determination)
to just look for localhost, and to not try to resolve anything.
Trusting non-public IPs does not work well (e.g. with lokinet where
all .loki addresses resolve to a local IP).
- ssl fingerprint option is removed; this isn't supported by curl
(because it is essentially just duplicating what a custom cainfo
bundle does)
- --daemon-ssl-allow-chained is removed; it wasn't a useful option (if
you don't want chaining, don't specify a cainfo chain).
- --daemon-address is now a URL instead of just host:port. (If you omit
the protocol, http:// is prepended).
- --daemon-host and --daemon-port are now deprecated and produce a
warning (in simplewallet) if used; the replacement is to use
--daemon-address.
- --daemon-ssl is deprecated; specify --daemon-address=https://whatever
instead.
- the above three are now hidden from --help
- reordered the wallet connection options to make more logical sense.
2020-07-26 22:29:49 +02:00
|
|
|
static std::optional<p2p_connection_context> public_connect(network_zone&, epee::net_utils::network_address const&);
|
|
|
|
static std::optional<p2p_connection_context> socks_connect(network_zone&, epee::net_utils::network_address const&);
|
2019-04-09 10:07:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* A `std::map` provides constant iterators and key/value pointers even with
|
|
|
|
inserts/erases to _other_ elements. This makes the configuration step easier
|
|
|
|
since references can safely be stored on the stack. Do not insert/erase
|
|
|
|
after configuration and before destruction, lock safety would need to be
|
|
|
|
added. `std::map::operator[]` WILL insert! */
|
|
|
|
std::map<epee::net_utils::zone, network_zone> m_network_zones;
|
|
|
|
|
2015-11-23 18:34:55 +01:00
|
|
|
|
2019-09-16 21:20:23 +02:00
|
|
|
std::map<std::string, time_t> m_conn_fails_cache;
|
Purge epee::critical_crap and CRITICAL_CRAP
This purges epee::critical_region/epee::critical_section and the awful
CRITICAL_REGION_LOCAL and CRITICAL_REGION_LOCAL1 and
CRITICAL_REGION_BEGIN1 and all that crap from epee code.
This wrapper class around a mutex is just painful, macro-infested
indirection that accomplishes nothing (and, worse, forces all using code
to use a std::recursive_mutex even when a different mutex type is more
appropriate).
This commit purges it, replacing the "critical_section" mutex wrappers
with either std::mutex, std::recursive_mutex, or std::shared_mutex as
appropriate. I kept anything that looked uncertain as a
recursive_mutex, simple cases that obviously don't recurse as
std::mutex, and simple cases with reader/writing mechanics as a
shared_mutex.
Ideally all the recursive_mutexes should be eliminated because a
recursive_mutex is almost always a design flaw where someone has let the
locking code get impossibly tangled, but that requires a lot more time
to properly trace down all the ways the mutexes are used.
Other notable changes:
- There was one NIH promise/future-like class here that was used in
example one place in p2p/net_node; I replaced it with a
std::promise/future.
- moved the mutex for LMDB resizing into LMDB itself; having it in the
abstract base class is bad design, and also made it impossible to make a
moveable base class (which gets used for the fake db classes in the test
code).
2020-06-22 21:40:31 +02:00
|
|
|
std::shared_mutex m_conn_fails_cache_lock;
|
2015-11-23 18:34:55 +01:00
|
|
|
|
Purge epee::critical_crap and CRITICAL_CRAP
This purges epee::critical_region/epee::critical_section and the awful
CRITICAL_REGION_LOCAL and CRITICAL_REGION_LOCAL1 and
CRITICAL_REGION_BEGIN1 and all that crap from epee code.
This wrapper class around a mutex is just painful, macro-infested
indirection that accomplishes nothing (and, worse, forces all using code
to use a std::recursive_mutex even when a different mutex type is more
appropriate).
This commit purges it, replacing the "critical_section" mutex wrappers
with either std::mutex, std::recursive_mutex, or std::shared_mutex as
appropriate. I kept anything that looked uncertain as a
recursive_mutex, simple cases that obviously don't recurse as
std::mutex, and simple cases with reader/writing mechanics as a
shared_mutex.
Ideally all the recursive_mutexes should be eliminated because a
recursive_mutex is almost always a design flaw where someone has let the
locking code get impossibly tangled, but that requires a lot more time
to properly trace down all the ways the mutexes are used.
Other notable changes:
- There was one NIH promise/future-like class here that was used in
example one place in p2p/net_node; I replaced it with a
std::promise/future.
- moved the mutex for LMDB resizing into LMDB itself; having it in the
abstract base class is bad design, and also made it impossible to make a
moveable base class (which gets used for the fake db classes in the test
code).
2020-06-22 21:40:31 +02:00
|
|
|
std::shared_mutex m_blocked_hosts_lock; // for both hosts and subnets
|
2019-09-16 21:20:23 +02:00
|
|
|
std::map<std::string, time_t> m_blocked_hosts;
|
2019-03-29 11:47:53 +01:00
|
|
|
std::map<epee::net_utils::ipv4_network_subnet, time_t> m_blocked_subnets;
|
2015-11-23 18:34:55 +01:00
|
|
|
|
Purge epee::critical_crap and CRITICAL_CRAP
This purges epee::critical_region/epee::critical_section and the awful
CRITICAL_REGION_LOCAL and CRITICAL_REGION_LOCAL1 and
CRITICAL_REGION_BEGIN1 and all that crap from epee code.
This wrapper class around a mutex is just painful, macro-infested
indirection that accomplishes nothing (and, worse, forces all using code
to use a std::recursive_mutex even when a different mutex type is more
appropriate).
This commit purges it, replacing the "critical_section" mutex wrappers
with either std::mutex, std::recursive_mutex, or std::shared_mutex as
appropriate. I kept anything that looked uncertain as a
recursive_mutex, simple cases that obviously don't recurse as
std::mutex, and simple cases with reader/writing mechanics as a
shared_mutex.
Ideally all the recursive_mutexes should be eliminated because a
recursive_mutex is almost always a design flaw where someone has let the
locking code get impossibly tangled, but that requires a lot more time
to properly trace down all the ways the mutexes are used.
Other notable changes:
- There was one NIH promise/future-like class here that was used in
example one place in p2p/net_node; I replaced it with a
std::promise/future.
- moved the mutex for LMDB resizing into LMDB itself; having it in the
abstract base class is bad design, and also made it impossible to make a
moveable base class (which gets used for the fake db classes in the test
code).
2020-06-22 21:40:31 +02:00
|
|
|
std::mutex m_host_fails_score_lock;
|
2017-05-27 12:35:54 +02:00
|
|
|
std::map<std::string, uint64_t> m_host_fails_score;
|
2017-03-18 00:39:47 +01:00
|
|
|
|
2020-06-02 01:01:24 +02:00
|
|
|
std::mutex m_used_stripe_peers_mutex;
|
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-30 00:30:51 +02:00
|
|
|
std::array<std::list<epee::net_utils::network_address>, 1 << CRYPTONOTE_PRUNING_LOG_STRIPES> m_used_stripe_peers;
|
|
|
|
|
2019-04-09 10:07:13 +02:00
|
|
|
boost::uuids::uuid m_network_id;
|
2018-02-16 12:04:04 +01:00
|
|
|
cryptonote::network_type m_nettype;
|
2014-03-03 23:07:58 +01:00
|
|
|
};
|
|
|
|
|
2018-10-31 22:47:20 +01:00
|
|
|
const int64_t default_limit_up = P2P_DEFAULT_LIMIT_RATE_UP; // kB/s
|
|
|
|
const int64_t default_limit_down = P2P_DEFAULT_LIMIT_RATE_DOWN; // kB/s
|
2017-11-29 23:53:58 +01:00
|
|
|
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_ip;
|
2019-04-11 00:34:30 +02:00
|
|
|
extern const command_line::arg_descriptor<std::string> arg_p2p_bind_ipv6_address;
|
2018-02-16 12:04:04 +01:00
|
|
|
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_port;
|
2019-04-11 00:34:30 +02:00
|
|
|
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_p2p_bind_port_ipv6;
|
|
|
|
extern const command_line::arg_descriptor<bool> arg_p2p_use_ipv6;
|
2019-10-13 15:27:46 +02:00
|
|
|
extern const command_line::arg_descriptor<bool> arg_p2p_ignore_ipv4;
|
2017-11-29 23:53:58 +01:00
|
|
|
extern const command_line::arg_descriptor<uint32_t> arg_p2p_external_port;
|
|
|
|
extern const command_line::arg_descriptor<bool> arg_p2p_allow_local_ip;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_peer;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_priority_node;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_exclusive_node;
|
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_seed_node;
|
2019-10-25 03:06:31 +02:00
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_tx_proxy;
|
2019-04-09 10:07:13 +02:00
|
|
|
extern const command_line::arg_descriptor<std::vector<std::string> > arg_anonymous_inbound;
|
2017-11-29 23:53:58 +01:00
|
|
|
extern const command_line::arg_descriptor<bool> arg_p2p_hide_my_port;
|
2019-02-25 02:31:45 +01:00
|
|
|
extern const command_line::arg_descriptor<bool> arg_no_sync;
|
2017-11-29 23:53:58 +01:00
|
|
|
|
|
|
|
extern const command_line::arg_descriptor<bool> arg_no_igd;
|
2019-06-06 12:28:02 +02:00
|
|
|
extern const command_line::arg_descriptor<std::string> arg_igd;
|
2017-11-29 23:53:58 +01:00
|
|
|
extern const command_line::arg_descriptor<bool> arg_offline;
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_out_peers;
|
2018-01-20 22:44:23 +01:00
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_in_peers;
|
2017-11-29 23:53:58 +01:00
|
|
|
extern const command_line::arg_descriptor<int> arg_tos_flag;
|
|
|
|
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_limit_rate_up;
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_limit_rate_down;
|
|
|
|
extern const command_line::arg_descriptor<int64_t> arg_limit_rate;
|
|
|
|
}
|
2014-03-03 23:07:58 +01:00
|
|
|
|
|
|
|
POP_WARNINGS
|
2019-04-09 10:07:13 +02:00
|
|
|
|