mirror of
https://github.com/monero-project/monero.git
synced 2025-05-07 08:24:59 -04:00
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:
parent
1e5cd3b35a
commit
973403bc9f
39 changed files with 4298 additions and 831 deletions
|
@ -33,6 +33,7 @@
|
|||
#include <boost/asio/io_service.hpp>
|
||||
#include <typeinfo>
|
||||
#include <type_traits>
|
||||
#include "enums.h"
|
||||
#include "serialization/keyvalue_serialization.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
|
@ -43,6 +44,11 @@
|
|||
#define MAKE_IP( a1, a2, a3, a4 ) (a1|(a2<<8)|(a3<<16)|(a4<<24))
|
||||
#endif
|
||||
|
||||
namespace net
|
||||
{
|
||||
class tor_address;
|
||||
}
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace net_utils
|
||||
|
@ -53,6 +59,10 @@ namespace net_utils
|
|||
uint16_t m_port;
|
||||
|
||||
public:
|
||||
constexpr ipv4_network_address() noexcept
|
||||
: ipv4_network_address(0, 0)
|
||||
{}
|
||||
|
||||
constexpr ipv4_network_address(uint32_t ip, uint16_t port) noexcept
|
||||
: m_ip(ip), m_port(port) {}
|
||||
|
||||
|
@ -67,9 +77,10 @@ namespace net_utils
|
|||
std::string host_str() const;
|
||||
bool is_loopback() const;
|
||||
bool is_local() const;
|
||||
static constexpr uint8_t get_type_id() noexcept { return ID; }
|
||||
static constexpr address_type get_type_id() noexcept { return address_type::ipv4; }
|
||||
static constexpr zone get_zone() noexcept { return zone::public_; }
|
||||
static constexpr bool is_blockable() noexcept { return true; }
|
||||
|
||||
static const uint8_t ID = 1;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(m_ip)
|
||||
KV_SERIALIZE(m_port)
|
||||
|
@ -103,7 +114,9 @@ namespace net_utils
|
|||
virtual std::string host_str() const = 0;
|
||||
virtual bool is_loopback() const = 0;
|
||||
virtual bool is_local() const = 0;
|
||||
virtual uint8_t get_type_id() const = 0;
|
||||
virtual address_type get_type_id() const = 0;
|
||||
virtual zone get_zone() const = 0;
|
||||
virtual bool is_blockable() const = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -131,7 +144,9 @@ namespace net_utils
|
|||
virtual std::string host_str() const override { return value.host_str(); }
|
||||
virtual bool is_loopback() const override { return value.is_loopback(); }
|
||||
virtual bool is_local() const override { return value.is_local(); }
|
||||
virtual uint8_t get_type_id() const override { return value.get_type_id(); }
|
||||
virtual address_type get_type_id() const override { return value.get_type_id(); }
|
||||
virtual zone get_zone() const override { return value.get_zone(); }
|
||||
virtual bool is_blockable() const override { return value.is_blockable(); }
|
||||
};
|
||||
|
||||
std::shared_ptr<interface> self;
|
||||
|
@ -146,6 +161,23 @@ namespace net_utils
|
|||
throw std::bad_cast{};
|
||||
return static_cast<implementation<Type_>*>(self_)->value;
|
||||
}
|
||||
|
||||
template<typename T, typename t_storage>
|
||||
bool serialize_addr(std::false_type, t_storage& stg, typename t_storage::hsection hparent)
|
||||
{
|
||||
T addr{};
|
||||
if (!epee::serialization::selector<false>::serialize(addr, stg, hparent, "addr"))
|
||||
return false;
|
||||
*this = std::move(addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T, typename t_storage>
|
||||
bool serialize_addr(std::true_type, t_storage& stg, typename t_storage::hsection hparent) const
|
||||
{
|
||||
return epee::serialization::selector<true>::serialize(as<T>(), stg, hparent, "addr");
|
||||
}
|
||||
|
||||
public:
|
||||
network_address() : self(nullptr) {}
|
||||
template<typename T>
|
||||
|
@ -158,43 +190,32 @@ namespace net_utils
|
|||
std::string host_str() const { return self ? self->host_str() : "<none>"; }
|
||||
bool is_loopback() const { return self ? self->is_loopback() : false; }
|
||||
bool is_local() const { return self ? self->is_local() : false; }
|
||||
uint8_t get_type_id() const { return self ? self->get_type_id() : 0; }
|
||||
address_type get_type_id() const { return self ? self->get_type_id() : address_type::invalid; }
|
||||
zone get_zone() const { return self ? self->get_zone() : zone::invalid; }
|
||||
bool is_blockable() const { return self ? self->is_blockable() : false; }
|
||||
template<typename Type> const Type &as() const { return as_mutable<const Type>(); }
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
uint8_t type = is_store ? this_ref.get_type_id() : 0;
|
||||
// need to `#include "net/tor_address.h"` when serializing `network_address`
|
||||
static constexpr std::integral_constant<bool, is_store> is_store_{};
|
||||
|
||||
std::uint8_t type = std::uint8_t(is_store ? this_ref.get_type_id() : address_type::invalid);
|
||||
if (!epee::serialization::selector<is_store>::serialize(type, stg, hparent_section, "type"))
|
||||
return false;
|
||||
switch (type)
|
||||
|
||||
switch (address_type(type))
|
||||
{
|
||||
case ipv4_network_address::ID:
|
||||
{
|
||||
if (!is_store)
|
||||
{
|
||||
const_cast<network_address&>(this_ref) = ipv4_network_address{0, 0};
|
||||
auto &addr = this_ref.template as_mutable<ipv4_network_address>();
|
||||
if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "addr"))
|
||||
MDEBUG("Found as addr: " << this_ref.str());
|
||||
else if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "template as<ipv4_network_address>()"))
|
||||
MDEBUG("Found as template as<ipv4_network_address>(): " << this_ref.str());
|
||||
else if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "template as_mutable<ipv4_network_address>()"))
|
||||
MDEBUG("Found as template as_mutable<ipv4_network_address>(): " << this_ref.str());
|
||||
else
|
||||
{
|
||||
MWARNING("Address not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto &addr = this_ref.template as_mutable<ipv4_network_address>();
|
||||
if (!epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "addr"))
|
||||
return false;
|
||||
}
|
||||
case address_type::ipv4:
|
||||
return this_ref.template serialize_addr<ipv4_network_address>(is_store_, stg, hparent_section);
|
||||
case address_type::tor:
|
||||
return this_ref.template serialize_addr<net::tor_address>(is_store_, stg, hparent_section);
|
||||
case address_type::invalid:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default: MERROR("Unsupported network address type: " << (unsigned)type); return false;
|
||||
}
|
||||
|
||||
MERROR("Unsupported network address type: " << (unsigned)type);
|
||||
return false;
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
@ -211,8 +232,6 @@ namespace net_utils
|
|||
inline bool operator>=(const network_address& lhs, const network_address& rhs)
|
||||
{ return !lhs.less(rhs); }
|
||||
|
||||
bool create_network_address(network_address &address, const std::string &string, uint16_t default_port = 0);
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
@ -250,7 +269,7 @@ namespace net_utils
|
|||
{}
|
||||
|
||||
connection_context_base(): m_connection_id(),
|
||||
m_remote_address(ipv4_network_address{0,0}),
|
||||
m_remote_address(),
|
||||
m_is_income(false),
|
||||
m_started(time(NULL)),
|
||||
m_last_recv(0),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue