Skip to content

Commit 251c64f

Browse files
committed
Merge pull request #7011
398e64c Better log message for unusable anon networks (hyc)
2 parents f690e49 + 398e64c commit 251c64f

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/cryptonote_protocol/levin_notify.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ namespace levin
233233
{
234234
struct zone
235235
{
236-
explicit zone(boost::asio::io_service& io_service, std::shared_ptr<connections> p2p, epee::byte_slice noise_in, bool is_public, bool pad_txs)
236+
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)
237237
: p2p(std::move(p2p)),
238238
noise(std::move(noise_in)),
239239
next_epoch(io_service),
@@ -243,7 +243,7 @@ namespace levin
243243
channels(),
244244
connection_count(0),
245245
flush_callbacks(0),
246-
is_public(is_public),
246+
nzone(zone),
247247
pad_txs(pad_txs),
248248
fluffing(false)
249249
{
@@ -260,7 +260,7 @@ namespace levin
260260
std::deque<noise_channel> channels; //!< Never touch after init; only update elements on `noise_channel.strand`
261261
std::atomic<std::size_t> connection_count; //!< Only update in strand, can be read at any time
262262
std::uint32_t flush_callbacks; //!< Number of active fluff flush callbacks queued
263-
const bool is_public; //!< Zone is public ipv4/ipv6 connections
263+
const epee::net_utils::zone nzone; //!< Zone is public ipv4/ipv6 connections, or i2p or tor
264264
const bool pad_txs; //!< Pad txs to the next boundary for privacy
265265
bool fluffing; //!< Zone is in Dandelion++ fluff epoch
266266
};
@@ -297,7 +297,8 @@ namespace levin
297297
if (!channel.connection.is_nil())
298298
channel.queue.push_back(std::move(message_));
299299
else if (destination_ == 0 && zone_->connection_count == 0)
300-
MWARNING("Unable to send transaction(s) over anonymity network - no available outbound connections");
300+
MWARNING("Unable to send transaction(s) to " << epee::net_utils::zone_to_string(zone_->nzone) <<
301+
" - no available outbound connections");
301302
}
302303
};
303304

@@ -399,7 +400,7 @@ namespace levin
399400
zone->p2p->foreach_connection([txs, now, &zone, &source, &in_duration, &out_duration, &next_flush] (detail::p2p_context& context)
400401
{
401402
// When i2p/tor, only fluff to outbound connections
402-
if (source != context.m_connection_id && (zone->is_public || !context.m_is_income))
403+
if (source != context.m_connection_id && (zone->nzone == epee::net_utils::zone::public_ || !context.m_is_income))
403404
{
404405
if (context.fluff_txs.empty())
405406
context.flush_time = now + (context.m_is_income ? in_duration() : out_duration());
@@ -562,7 +563,7 @@ namespace levin
562563

563564
assert(zone_->strand.running_in_this_thread());
564565

565-
if (zone_->is_public)
566+
if (zone_->nzone == epee::net_utils::zone::public_)
566567
MDEBUG("Starting new Dandelion++ epoch: " << (fluffing_ ? "fluff" : "stem"));
567568

568569
zone_->map = std::move(map_);
@@ -630,10 +631,12 @@ namespace levin
630631
{
631632
channel.active = nullptr;
632633
channel.connection = boost::uuids::nil_uuid();
634+
auto height = core_->get_target_blockchain_height();
633635

634-
auto connections = get_out_connections(*zone_->p2p, core_->get_target_blockchain_height());
636+
auto connections = get_out_connections(*zone_->p2p, height);
635637
if (connections.empty())
636-
MWARNING("Lost all outbound connections to anonymity network - currently unable to send transaction(s)");
638+
MWARNING("Unable to send transaction(s) to " << epee::net_utils::zone_to_string(zone_->nzone) <<
639+
" - no suitable outbound connections at height " << height);
637640

638641
zone_->strand.post(update_channels{zone_, std::move(connections)});
639642
}
@@ -676,15 +679,15 @@ namespace levin
676679
};
677680
} // anonymous
678681

679-
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)
680-
: zone_(std::make_shared<detail::zone>(service, std::move(p2p), std::move(noise), is_public, pad_txs))
682+
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)
683+
: zone_(std::make_shared<detail::zone>(service, std::move(p2p), std::move(noise), zone, pad_txs))
681684
, core_(std::addressof(core))
682685
{
683686
if (!zone_->p2p)
684687
throw std::logic_error{"cryptonote::levin::notify cannot have nullptr p2p argument"};
685688

686689
const bool noise_enabled = !zone_->noise.empty();
687-
if (noise_enabled || is_public)
690+
if (noise_enabled || zone == epee::net_utils::zone::public_)
688691
{
689692
const auto now = std::chrono::steady_clock::now();
690693
const auto min_epoch = noise_enabled ? noise_min_epoch : dandelionpp_min_epoch;
@@ -806,7 +809,7 @@ namespace levin
806809
case relay_method::stem:
807810
case relay_method::forward:
808811
case relay_method::local:
809-
if (zone_->is_public)
812+
if (zone_->nzone == epee::net_utils::zone::public_)
810813
{
811814
// this will change a local/forward tx to stem or fluff ...
812815
zone_->strand.dispatch(

src/cryptonote_protocol/levin_notify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace levin
8585
{}
8686

8787
//! Construct an instance with available notification `zones`.
88-
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);
88+
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);
8989

9090
notify(const notify&) = delete;
9191
notify(notify&&) = default;

src/p2p/net_node.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ namespace nodetool
402402
m_use_ipv6 = command_line::get_arg(vm, arg_p2p_use_ipv6);
403403
m_require_ipv4 = !command_line::get_arg(vm, arg_p2p_ignore_ipv4);
404404
public_zone.m_notifier = cryptonote::levin::notify{
405-
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()
405+
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()
406406
};
407407

408408
if (command_line::has_arg(vm, arg_p2p_add_peer))
@@ -545,7 +545,7 @@ namespace nodetool
545545
}
546546

547547
zone.m_notifier = cryptonote::levin::notify{
548-
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()
548+
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()
549549
};
550550
}
551551

tests/unit_tests/levin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ namespace
329329
epee::byte_slice noise = nullptr;
330330
if (noise_size)
331331
noise = epee::levin::make_noise_notify(noise_size);
332-
return cryptonote::levin::notify{io_service_, connections_, std::move(noise), is_public, pad_txs, events_};
332+
epee::net_utils::zone zone = is_public ? epee::net_utils::zone::public_ : epee::net_utils::zone::i2p;
333+
return cryptonote::levin::notify{io_service_, connections_, std::move(noise), zone, pad_txs, events_};
333334
}
334335

335336
boost::uuids::random_generator random_generator_;

0 commit comments

Comments
 (0)