Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store and forward the original peering port in keepalive messages #3878

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nano/node/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,16 @@ class network_message_visitor : public nano::message_visitor
}
node.stats.inc (nano::stat::type::message, nano::stat::detail::keepalive, nano::stat::dir::in);
node.network.merge_peers (message_a.peers);

// Check for special node port data
auto peer0 (message_a.peers[0]);
if (peer0.address () == boost::asio::ip::address_v6{} && peer0.port () != 0)
{
nano::endpoint new_endpoint (channel->get_tcp_endpoint ().address (), peer0.port ());
node.network.merge_peer (new_endpoint);

// Remember this for future forwarding to other peers
channel->set_peering_endpoint (new_endpoint);
}
}
void publish (nano::publish const & message_a) override
Expand Down Expand Up @@ -652,9 +656,9 @@ void nano::network::random_fill (std::array<nano::endpoint, 8> & target_a) const
auto j (target_a.begin ());
for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i, ++j)
{
debug_assert ((*i)->get_endpoint ().address ().is_v6 ());
debug_assert ((*i)->get_peering_endpoint ().address ().is_v6 ());
debug_assert (j < target_a.end ());
*j = (*i)->get_endpoint ();
*j = (*i)->get_peering_endpoint ();
}
}

Expand Down
2 changes: 1 addition & 1 deletion nano/node/transport/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ nano::tcp_endpoint nano::transport::tcp_channels::bootstrap_peer (uint8_t connec
{
if (i->channel->get_network_version () >= connection_protocol_version_min)
{
result = i->endpoint ();
result = nano::transport::map_endpoint_to_tcp (i->channel->get_peering_endpoint ());
channels.get<last_bootstrap_attempt_tag> ().modify (i, [] (channel_tcp_wrapper & wrapper_a) {
wrapper_a.channel->set_last_bootstrap_attempt (std::chrono::steady_clock::now ());
});
Expand Down
17 changes: 17 additions & 0 deletions nano/node/transport/transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ void nano::transport::channel::send (nano::message & message_a, std::function<vo
}
}

void nano::transport::channel::set_peering_endpoint (nano::endpoint endpoint)
{
peering_endpoint = endpoint;
}

nano::endpoint nano::transport::channel::get_peering_endpoint () const
{
if (peering_endpoint)
{
return *peering_endpoint;
}
else
{
return get_endpoint ();
}
}

boost::asio::ip::address_v6 nano::transport::mapped_from_v4_bytes (unsigned long address_a)
{
return boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (address_a));
Expand Down
4 changes: 4 additions & 0 deletions nano/node/transport/transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ namespace transport
network_version = network_version_a;
}

nano::endpoint get_peering_endpoint () const;
void set_peering_endpoint (nano::endpoint endpoint);

mutable nano::mutex channel_mutex;

private:
Expand All @@ -142,6 +145,7 @@ namespace transport
std::chrono::steady_clock::time_point last_packet_sent{ std::chrono::steady_clock::now () };
boost::optional<nano::account> node_id{ boost::none };
std::atomic<uint8_t> network_version{ 0 };
std::optional<nano::endpoint> peering_endpoint{};

protected:
nano::node & node;
Expand Down