Adding initial support for broadcasting transactions over Tor

- Support for ".onion" in --add-exclusive-node and --add-peer
  - Add --anonymizing-proxy for outbound Tor connections
  - Add --anonymous-inbounds for inbound Tor connections
  - Support for sharing ".onion" addresses over Tor connections
  - Support for broadcasting transactions received over RPC exclusively
    over Tor (else broadcast over public IP when Tor not enabled).
This commit is contained in:
Lee Clagett 2018-12-16 17:57:44 +00:00
parent 1e5cd3b35a
commit 973403bc9f
39 changed files with 4298 additions and 831 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2018, The Monero Project
// Copyright (c) 2014-2018, The Monero Project
//
// All rights reserved.
//
@ -30,7 +30,11 @@
#pragma once
#include <cstring>
#include "common/expect.h"
#include "net/net_utils_base.h"
#include "net/tor_address.h"
#include "p2p/p2p_protocol_defs.h"
#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
@ -42,24 +46,37 @@ namespace boost
namespace serialization
{
template <class T, class Archive>
inline void do_serialize(Archive &a, epee::net_utils::network_address& na, T local)
inline void do_serialize(boost::mpl::false_, Archive &a, epee::net_utils::network_address& na)
{
if (typename Archive::is_saving()) local = na.as<T>();
a & local;
if (!typename Archive::is_saving()) na = local;
T addr{};
a & addr;
na = std::move(addr);
}
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>();
}
template <class Archive, class ver_type>
inline void serialize(Archive &a, epee::net_utils::network_address& na, const ver_type ver)
{
static constexpr const typename Archive::is_saving is_saving{};
uint8_t type;
if (typename Archive::is_saving())
type = na.get_type_id();
if (is_saving)
type = uint8_t(na.get_type_id());
a & type;
switch (type)
switch (epee::net_utils::address_type(type))
{
case epee::net_utils::ipv4_network_address::ID:
do_serialize(a, na, epee::net_utils::ipv4_network_address{0, 0});
break;
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;
case epee::net_utils::address_type::invalid:
default:
throw std::runtime_error("Unsupported network address type");
}
@ -75,6 +92,47 @@ namespace boost
na = epee::net_utils::ipv4_network_address{ip, port};
}
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);
}
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;
if (length > net::tor_address::buffer_size())
MONERO_THROW(net::error::invalid_tor_address, "Tor address too long");
char host[net::tor_address::buffer_size()] = {0};
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));
}
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, nodetool::peerlist_entry& pl, const ver_type ver)
{