Better log message for unusable anon networks

This commit is contained in:
Howard Chu 2020-11-11 00:01:24 +00:00
parent 83f1d863bd
commit 91fd634768
No known key found for this signature in database
GPG key ID: FD2A70B44AB11BA7
4 changed files with 20 additions and 16 deletions

View file

@ -233,7 +233,7 @@ namespace levin
{ {
struct zone struct zone
{ {
explicit zone(boost::asio::io_service& io_service, std::shared_ptr<connections> p2p, epee::byte_slice noise_in, bool is_public, bool pad_txs) explicit zone(boost::asio::io_service& io_service, std::shared_ptr<connections> p2p, epee::byte_slice noise_in, epee::net_utils::zone zone, bool pad_txs)
: p2p(std::move(p2p)), : p2p(std::move(p2p)),
noise(std::move(noise_in)), noise(std::move(noise_in)),
next_epoch(io_service), next_epoch(io_service),
@ -243,7 +243,7 @@ namespace levin
channels(), channels(),
flush_time(std::chrono::steady_clock::time_point::max()), flush_time(std::chrono::steady_clock::time_point::max()),
connection_count(0), connection_count(0),
is_public(is_public), nzone(zone),
pad_txs(pad_txs), pad_txs(pad_txs),
fluffing(false) fluffing(false)
{ {
@ -260,7 +260,7 @@ namespace levin
std::deque<noise_channel> channels; //!< Never touch after init; only update elements on `noise_channel.strand` std::deque<noise_channel> channels; //!< Never touch after init; only update elements on `noise_channel.strand`
std::chrono::steady_clock::time_point flush_time; //!< Next expected Dandelion++ fluff flush std::chrono::steady_clock::time_point flush_time; //!< Next expected Dandelion++ fluff flush
std::atomic<std::size_t> connection_count; //!< Only update in strand, can be read at any time std::atomic<std::size_t> connection_count; //!< Only update in strand, can be read at any time
const bool is_public; //!< Zone is public ipv4/ipv6 connections const epee::net_utils::zone nzone; //!< Zone is public ipv4/ipv6 connections, or i2p or tor
const bool pad_txs; //!< Pad txs to the next boundary for privacy const bool pad_txs; //!< Pad txs to the next boundary for privacy
bool fluffing; //!< Zone is in Dandelion++ fluff epoch bool fluffing; //!< Zone is in Dandelion++ fluff epoch
}; };
@ -297,7 +297,8 @@ namespace levin
if (!channel.connection.is_nil()) if (!channel.connection.is_nil())
channel.queue.push_back(std::move(message_)); channel.queue.push_back(std::move(message_));
else if (destination_ == 0 && zone_->connection_count == 0) else if (destination_ == 0 && zone_->connection_count == 0)
MWARNING("Unable to send transaction(s) over anonymity network - no available outbound connections"); MWARNING("Unable to send transaction(s) to " << epee::net_utils::zone_to_string(zone_->nzone) <<
" - no available outbound connections");
} }
}; };
@ -410,7 +411,7 @@ namespace levin
zone->p2p->foreach_connection([txs, now, &zone, &source, &in_duration, &out_duration, &next_flush, &available] (detail::p2p_context& context) zone->p2p->foreach_connection([txs, now, &zone, &source, &in_duration, &out_duration, &next_flush, &available] (detail::p2p_context& context)
{ {
// When i2p/tor, only fluff to outbound connections // When i2p/tor, only fluff to outbound connections
if (source != context.m_connection_id && (zone->is_public || !context.m_is_income)) if (source != context.m_connection_id && (zone->nzone == epee::net_utils::zone::public_ || !context.m_is_income))
{ {
available = true; available = true;
if (context.fluff_txs.empty()) if (context.fluff_txs.empty())
@ -577,7 +578,7 @@ namespace levin
assert(zone_->strand.running_in_this_thread()); assert(zone_->strand.running_in_this_thread());
if (zone_->is_public) if (zone_->nzone == epee::net_utils::zone::public_)
MDEBUG("Starting new Dandelion++ epoch: " << (fluffing_ ? "fluff" : "stem")); MDEBUG("Starting new Dandelion++ epoch: " << (fluffing_ ? "fluff" : "stem"));
zone_->map = std::move(map_); zone_->map = std::move(map_);
@ -645,10 +646,12 @@ namespace levin
{ {
channel.active = nullptr; channel.active = nullptr;
channel.connection = boost::uuids::nil_uuid(); channel.connection = boost::uuids::nil_uuid();
auto height = core_->get_target_blockchain_height();
auto connections = get_out_connections(*zone_->p2p, core_->get_target_blockchain_height()); auto connections = get_out_connections(*zone_->p2p, height);
if (connections.empty()) if (connections.empty())
MWARNING("Lost all outbound connections to anonymity network - currently unable to send transaction(s)"); MWARNING("Unable to send transaction(s) to " << epee::net_utils::zone_to_string(zone_->nzone) <<
" - no suitable outbound connections at height " << height);
zone_->strand.post(update_channels{zone_, std::move(connections)}); zone_->strand.post(update_channels{zone_, std::move(connections)});
} }
@ -691,15 +694,15 @@ namespace levin
}; };
} // anonymous } // anonymous
notify::notify(boost::asio::io_service& service, std::shared_ptr<connections> p2p, epee::byte_slice noise, const bool is_public, const bool pad_txs, i_core_events& core) notify::notify(boost::asio::io_service& service, std::shared_ptr<connections> p2p, epee::byte_slice noise, epee::net_utils::zone zone, const bool pad_txs, i_core_events& core)
: zone_(std::make_shared<detail::zone>(service, std::move(p2p), std::move(noise), is_public, pad_txs)) : zone_(std::make_shared<detail::zone>(service, std::move(p2p), std::move(noise), zone, pad_txs))
, core_(std::addressof(core)) , core_(std::addressof(core))
{ {
if (!zone_->p2p) if (!zone_->p2p)
throw std::logic_error{"cryptonote::levin::notify cannot have nullptr p2p argument"}; throw std::logic_error{"cryptonote::levin::notify cannot have nullptr p2p argument"};
const bool noise_enabled = !zone_->noise.empty(); const bool noise_enabled = !zone_->noise.empty();
if (noise_enabled || is_public) if (noise_enabled || zone == epee::net_utils::zone::public_)
{ {
const auto now = std::chrono::steady_clock::now(); const auto now = std::chrono::steady_clock::now();
const auto min_epoch = noise_enabled ? noise_min_epoch : dandelionpp_min_epoch; const auto min_epoch = noise_enabled ? noise_min_epoch : dandelionpp_min_epoch;
@ -821,7 +824,7 @@ namespace levin
case relay_method::stem: case relay_method::stem:
case relay_method::forward: case relay_method::forward:
case relay_method::local: case relay_method::local:
if (zone_->is_public) if (zone_->nzone == epee::net_utils::zone::public_)
{ {
// this will change a local/forward tx to stem or fluff ... // this will change a local/forward tx to stem or fluff ...
zone_->strand.dispatch( zone_->strand.dispatch(

View file

@ -85,7 +85,7 @@ namespace levin
{} {}
//! Construct an instance with available notification `zones`. //! Construct an instance with available notification `zones`.
explicit notify(boost::asio::io_service& service, std::shared_ptr<connections> p2p, epee::byte_slice noise, bool is_public, bool pad_txs, i_core_events& core); explicit notify(boost::asio::io_service& service, std::shared_ptr<connections> p2p, epee::byte_slice noise, epee::net_utils::zone zone, bool pad_txs, i_core_events& core);
notify(const notify&) = delete; notify(const notify&) = delete;
notify(notify&&) = default; notify(notify&&) = default;

View file

@ -386,7 +386,7 @@ namespace nodetool
m_use_ipv6 = command_line::get_arg(vm, arg_p2p_use_ipv6); m_use_ipv6 = command_line::get_arg(vm, arg_p2p_use_ipv6);
m_require_ipv4 = !command_line::get_arg(vm, arg_p2p_ignore_ipv4); m_require_ipv4 = !command_line::get_arg(vm, arg_p2p_ignore_ipv4);
public_zone.m_notifier = cryptonote::levin::notify{ public_zone.m_notifier = cryptonote::levin::notify{
public_zone.m_net_server.get_io_service(), public_zone.m_net_server.get_config_shared(), nullptr, true, pad_txs, m_payload_handler.get_core() public_zone.m_net_server.get_io_service(), public_zone.m_net_server.get_config_shared(), nullptr, epee::net_utils::zone::public_, pad_txs, m_payload_handler.get_core()
}; };
if (command_line::has_arg(vm, arg_p2p_add_peer)) if (command_line::has_arg(vm, arg_p2p_add_peer))
@ -499,7 +499,7 @@ namespace nodetool
} }
zone.m_notifier = cryptonote::levin::notify{ zone.m_notifier = cryptonote::levin::notify{
zone.m_net_server.get_io_service(), zone.m_net_server.get_config_shared(), std::move(this_noise), false, pad_txs, m_payload_handler.get_core() zone.m_net_server.get_io_service(), zone.m_net_server.get_config_shared(), std::move(this_noise), proxy.zone, pad_txs, m_payload_handler.get_core()
}; };
} }

View file

@ -329,7 +329,8 @@ namespace
epee::byte_slice noise = nullptr; epee::byte_slice noise = nullptr;
if (noise_size) if (noise_size)
noise = epee::levin::make_noise_notify(noise_size); noise = epee::levin::make_noise_notify(noise_size);
return cryptonote::levin::notify{io_service_, connections_, std::move(noise), is_public, pad_txs, events_}; epee::net_utils::zone zone = is_public ? epee::net_utils::zone::public_ : epee::net_utils::zone::i2p;
return cryptonote::levin::notify{io_service_, connections_, std::move(noise), zone, pad_txs, events_};
} }
boost::uuids::random_generator random_generator_; boost::uuids::random_generator random_generator_;