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

Remove channel comparison functions #4500

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
2 changes: 0 additions & 2 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,6 @@ TEST (network, loopback_channel)
ASSERT_EQ (channel1.get_node_id (), node1.node_id.pub);
ASSERT_EQ (channel1.get_node_id_optional ().value_or (0), node1.node_id.pub);
nano::transport::inproc::channel channel2 (node2, node2);
ASSERT_EQ (channel1, channel1);
ASSERT_FALSE (channel1 == channel2);
++node1.network.port;
ASSERT_NE (channel1.get_endpoint (), node1.network.endpoint ());
}
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/rep_crawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TEST (rep_crawler, rep_weight)
ASSERT_EQ (1, reps.size ());
ASSERT_EQ (node.balance (nano::dev::genesis_key.pub), node.ledger.weight (reps[0].account));
ASSERT_EQ (nano::dev::genesis_key.pub, reps[0].account);
ASSERT_EQ (*channel1, *reps[0].channel);
ASSERT_EQ (channel1, reps[0].channel);
ASSERT_TRUE (node.rep_crawler.is_pr (channel1));
ASSERT_FALSE (node.rep_crawler.is_pr (channel2));
ASSERT_TRUE (node.rep_crawler.is_pr (channel3));
Expand Down Expand Up @@ -189,7 +189,7 @@ TEST (rep_crawler, rep_remove)
ASSERT_EQ (1, reps.size ());
ASSERT_EQ (searching_node.minimum_principal_weight () * 2, searching_node.ledger.weight (reps[0].account));
ASSERT_EQ (keys_rep1.pub, reps[0].account);
ASSERT_EQ (*channel_rep1, *reps[0].channel);
ASSERT_EQ (channel_rep1, reps[0].channel);

// When rep1 disconnects then rep1 should not be found anymore
channel_rep1->close ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/bootstrap/bootstrap_connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ nano::bootstrap_client::bootstrap_client (std::shared_ptr<nano::node> const & no
{
++node_a->bootstrap_initiator.connections->connections_count;
receive_buffer->resize (256);
channel->set_endpoint ();
channel->update_endpoint ();
}

nano::bootstrap_client::~bootstrap_client ()
Expand Down
47 changes: 1 addition & 46 deletions nano/node/transport/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class channel
explicit channel (nano::node &);
virtual ~channel () = default;

virtual std::size_t hash_code () const = 0;
virtual bool operator== (nano::transport::channel const &) const = 0;

void send (nano::message & message_a,
std::function<void (boost::system::error_code const &, std::size_t)> const & callback_a = nullptr,
nano::transport::buffer_drop_policy policy_a = nano::transport::buffer_drop_policy::limiter,
Expand Down Expand Up @@ -148,46 +145,4 @@ class channel
public: // Logging
virtual void operator() (nano::object_stream &) const;
};
}

namespace std
{
template <>
struct hash<::nano::transport::channel>
{
std::size_t operator() (::nano::transport::channel const & channel_a) const
{
return channel_a.hash_code ();
}
};
template <>
struct equal_to<std::reference_wrapper<::nano::transport::channel const>>
{
bool operator() (std::reference_wrapper<::nano::transport::channel const> const & lhs, std::reference_wrapper<::nano::transport::channel const> const & rhs) const
{
return lhs.get () == rhs.get ();
}
};
}

namespace boost
{
template <>
struct hash<::nano::transport::channel>
{
std::size_t operator() (::nano::transport::channel const & channel_a) const
{
std::hash<::nano::transport::channel> hash;
return hash (channel_a);
}
};
template <>
struct hash<std::reference_wrapper<::nano::transport::channel const>>
{
std::size_t operator() (std::reference_wrapper<::nano::transport::channel const> const & channel_a) const
{
std::hash<::nano::transport::channel> hash;
return hash (channel_a.get ());
}
};
}
}
16 changes: 0 additions & 16 deletions nano/node/transport/fake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ void nano::transport::fake::channel::send_buffer (nano::shared_const_buffer cons
}
}

std::size_t nano::transport::fake::channel::hash_code () const
{
std::hash<::nano::endpoint> hash;
return hash (endpoint);
}

bool nano::transport::fake::channel::operator== (nano::transport::channel const & other_a) const
{
return endpoint == other_a.get_endpoint ();
}

bool nano::transport::fake::channel::operator== (nano::transport::fake::channel const & other_a) const
{
return endpoint == other_a.get_endpoint ();
}

std::string nano::transport::fake::channel::to_string () const
{
return boost::str (boost::format ("%1%") % endpoint);
Expand Down
4 changes: 0 additions & 4 deletions nano/node/transport/fake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ namespace transport
explicit channel (nano::node &);

std::string to_string () const override;
std::size_t hash_code () const override;

void send_buffer (
nano::shared_const_buffer const &,
std::function<void (boost::system::error_code const &, std::size_t)> const & = nullptr,
nano::transport::buffer_drop_policy = nano::transport::buffer_drop_policy::limiter,
nano::transport::traffic_type = nano::transport::traffic_type::generic) override;

bool operator== (nano::transport::channel const &) const override;
bool operator== (nano::transport::fake::channel const & other_a) const;

void set_endpoint (nano::endpoint const & endpoint_a)
{
endpoint = endpoint_a;
Expand Down
11 changes: 0 additions & 11 deletions nano/node/transport/inproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ nano::transport::inproc::channel::channel (nano::node & node, nano::node & desti
set_network_version (node.network_params.network.protocol_version);
}

std::size_t nano::transport::inproc::channel::hash_code () const
{
std::hash<::nano::endpoint> hash;
return hash (endpoint);
}

bool nano::transport::inproc::channel::operator== (nano::transport::channel const & other_a) const
{
return endpoint == other_a.get_endpoint ();
}

/**
* Send the buffer to the peer and call the callback function when done. The call never fails.
* Note that the inbound message visitor will be called before the callback because it is called directly whereas the callback is spawned in the background.
Expand Down
6 changes: 0 additions & 6 deletions nano/node/transport/inproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ namespace transport
{
public:
explicit channel (nano::node & node, nano::node & destination);
std::size_t hash_code () const override;
bool operator== (nano::transport::channel const &) const override;

// TODO: investigate clang-tidy warning about default parameters on virtual/override functions
void send_buffer (nano::shared_const_buffer const &, std::function<void (boost::system::error_code const &, std::size_t)> const & = nullptr, nano::transport::buffer_drop_policy = nano::transport::buffer_drop_policy::limiter, nano::transport::traffic_type = nano::transport::traffic_type::generic) override;

std::string to_string () const override;
bool operator== (nano::transport::inproc::channel const & other_a) const
{
return endpoint == other_a.get_endpoint ();
}

nano::endpoint get_endpoint () const override
{
Expand Down
32 changes: 2 additions & 30 deletions nano/node/transport/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,6 @@ nano::transport::channel_tcp::~channel_tcp ()
}
}

std::size_t nano::transport::channel_tcp::hash_code () const
{
std::hash<::nano::tcp_endpoint> hash;
return hash (get_tcp_endpoint ());
}

bool nano::transport::channel_tcp::operator== (nano::transport::channel const & other_a) const
{
bool result (false);
auto other_l (dynamic_cast<nano::transport::channel_tcp const *> (&other_a));
if (other_l != nullptr)
{
return *this == *other_l;
}
return result;
}

void nano::transport::channel_tcp::send_buffer (nano::shared_const_buffer const & buffer_a, std::function<void (boost::system::error_code const &, std::size_t)> const & callback_a, nano::transport::buffer_drop_policy policy_a, nano::transport::traffic_type traffic_type)
{
if (auto socket_l = socket.lock ())
Expand Down Expand Up @@ -102,17 +85,6 @@ std::string nano::transport::channel_tcp::to_string () const
return nano::util::to_str (get_tcp_endpoint ());
}

void nano::transport::channel_tcp::set_endpoint ()
{
nano::lock_guard<nano::mutex> lk{ channel_mutex };
debug_assert (endpoint == nano::tcp_endpoint (boost::asio::ip::address_v6::any (), 0)); // Not initialized endpoint value
// Calculate TCP socket endpoint
if (auto socket_l = socket.lock ())
{
endpoint = socket_l->remote_endpoint ();
}
}

void nano::transport::channel_tcp::operator() (nano::object_stream & obs) const
{
nano::transport::channel::operator() (obs); // Write common data
Expand Down Expand Up @@ -367,7 +339,7 @@ void nano::transport::tcp_channels::process_message (nano::message const & messa
{
// Add temporary channel
auto temporary_channel (std::make_shared<nano::transport::channel_tcp> (node, socket_a));
temporary_channel->set_endpoint ();
temporary_channel->update_endpoint ();
debug_assert (endpoint_a == temporary_channel->get_tcp_endpoint ());
temporary_channel->set_node_id (node_id_a);
temporary_channel->set_network_version (message_a.header.version_using);
Expand Down Expand Up @@ -625,7 +597,7 @@ void nano::transport::tcp_channels::start_tcp (nano::endpoint const & endpoint_a
nano::util::to_str (endpoint_a),
(query ? query->cookie.to_string () : "<none>"));

channel->set_endpoint ();
channel->update_endpoint ();
std::shared_ptr<std::vector<uint8_t>> receive_buffer (std::make_shared<std::vector<uint8_t>> ());
receive_buffer->resize (256);
channel->send (message, [node_w, channel, endpoint_a, receive_buffer] (boost::system::error_code const & ec, std::size_t size_a) {
Expand Down
15 changes: 8 additions & 7 deletions nano/node/transport/tcp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ namespace transport
channel_tcp (nano::node &, std::weak_ptr<nano::transport::socket>);
~channel_tcp () override;

std::size_t hash_code () const override;
bool operator== (nano::transport::channel const &) const override;

// TODO: investigate clang-tidy warning about default parameters on virtual/override functions//
void send_buffer (nano::shared_const_buffer const &, std::function<void (boost::system::error_code const &, std::size_t)> const & = nullptr, nano::transport::buffer_drop_policy = nano::transport::buffer_drop_policy::limiter, nano::transport::traffic_type = nano::transport::traffic_type::generic) override;

std::string to_string () const override;
bool operator== (nano::transport::channel_tcp const & other_a) const

void update_endpoint ()
{
return &node == &other_a.node && socket.lock () == other_a.socket.lock ();
nano::lock_guard<nano::mutex> lk (channel_mutex);
debug_assert (endpoint == nano::tcp_endpoint (boost::asio::ip::address_v6::any (), 0)); // Not initialized endpoint value
if (auto socket_l = socket.lock ())
{
endpoint = socket_l->remote_endpoint ();
}
}

void set_endpoint ();

nano::endpoint get_endpoint () const override
{
return nano::transport::map_tcp_to_endpoint (get_tcp_endpoint ());
Expand Down
Loading