diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index f5dd614b3..3c497ebed 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index dfbd1a360..1b085c394 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/core_test/fakes/work_peer.hpp b/nano/core_test/fakes/work_peer.hpp index bff40fee2..52eb8ff88 100644 --- a/nano/core_test/fakes/work_peer.hpp +++ b/nano/core_test/fakes/work_peer.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/core_test/message.cpp b/nano/core_test/message.cpp index 60d233821..e18c09c6c 100644 --- a/nano/core_test/message.cpp +++ b/nano/core_test/message.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/core_test/network_filter.cpp b/nano/core_test/network_filter.cpp index 788d7c271..12e816e2e 100644 --- a/nano/core_test/network_filter.cpp +++ b/nano/core_test/network_filter.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include @@ -163,4 +163,4 @@ TEST (network_filter, expire) ASSERT_FALSE (filter.check (2)); // Entry with epoch 1 should be expired ASSERT_FALSE (filter.apply (2)); // Entry with epoch 1 should be replaced -} \ No newline at end of file +} diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 3389a8a96..241cd347b 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index fc87e502f..c27e6c0bb 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -59,8 +59,6 @@ add_library( bootstrap_ascending/service.cpp cli.hpp cli.cpp - common.hpp - common.cpp confirming_set.hpp confirming_set.cpp confirmation_solicitor.hpp @@ -76,6 +74,9 @@ add_library( election_behavior.hpp election_insertion_result.hpp election_status.hpp + endpoint.cpp + endpoint.hpp + endpoint_templ.hpp epoch_upgrader.hpp epoch_upgrader.cpp fair_queue.hpp diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 8779400ee..fe021ffd2 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index f06f83196..b02cd56fd 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_bulk_push.hpp b/nano/node/bootstrap/bootstrap_bulk_push.hpp index d40e0fe5a..19f8db764 100644 --- a/nano/node/bootstrap/bootstrap_bulk_push.hpp +++ b/nano/node/bootstrap/bootstrap_bulk_push.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/node/bootstrap/bootstrap_connections.cpp b/nano/node/bootstrap/bootstrap_connections.cpp index b3f1334b8..62e7bc07b 100644 --- a/nano/node/bootstrap/bootstrap_connections.cpp +++ b/nano/node/bootstrap/bootstrap_connections.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_connections.hpp b/nano/node/bootstrap/bootstrap_connections.hpp index d246c23bb..ee86e32a5 100644 --- a/nano/node/bootstrap/bootstrap_connections.hpp +++ b/nano/node/bootstrap/bootstrap_connections.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 2f8807439..79bbce58a 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 5ebe67bbf..fd65b4e3a 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/nano/node/distributed_work.hpp b/nano/node/distributed_work.hpp index 17edecc60..4d83e0160 100644 --- a/nano/node/distributed_work.hpp +++ b/nano/node/distributed_work.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include diff --git a/nano/node/common.cpp b/nano/node/endpoint.cpp similarity index 94% rename from nano/node/common.cpp rename to nano/node/endpoint.cpp index 5edab1f7f..ccfd7361f 100644 --- a/nano/node/common.cpp +++ b/nano/node/endpoint.cpp @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include @@ -27,6 +27,12 @@ uint64_t nano::ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint1 return result; } +uint64_t nano::endpoint_hash_raw (nano::endpoint const & endpoint_a) +{ + uint64_t result (nano::ip_address_hash_raw (endpoint_a.address (), endpoint_a.port ())); + return result; +} + bool nano::parse_port (std::string const & string_a, uint16_t & port_a) { bool result = false; diff --git a/nano/node/common.hpp b/nano/node/endpoint.hpp similarity index 61% rename from nano/node/common.hpp rename to nano/node/endpoint.hpp index 92613306e..c1ed629ef 100644 --- a/nano/node/common.hpp +++ b/nano/node/endpoint.hpp @@ -1,9 +1,10 @@ #pragma once -#include #include +#include #include +#include namespace boost::asio::ip { @@ -19,16 +20,11 @@ bool parse_endpoint (std::string const &, nano::endpoint &); std::optional parse_endpoint (std::string const &); bool parse_tcp_endpoint (std::string const &, nano::tcp_endpoint &); uint64_t ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint16_t port = 0); +uint64_t endpoint_hash_raw (nano::endpoint const & endpoint_a); } namespace { -uint64_t endpoint_hash_raw (nano::endpoint const & endpoint_a) -{ - uint64_t result (nano::ip_address_hash_raw (endpoint_a.address (), endpoint_a.port ())); - return result; -} - template struct endpoint_hash { @@ -39,7 +35,7 @@ struct endpoint_hash<8> { std::size_t operator() (nano::endpoint const & endpoint_a) const { - return endpoint_hash_raw (endpoint_a); + return nano::endpoint_hash_raw (endpoint_a); } }; @@ -48,7 +44,7 @@ struct endpoint_hash<4> { std::size_t operator() (nano::endpoint const & endpoint_a) const { - uint64_t big (endpoint_hash_raw (endpoint_a)); + uint64_t big = nano::endpoint_hash_raw (endpoint_a); uint32_t result (static_cast (big) ^ static_cast (big >> 32)); return result; } @@ -83,47 +79,19 @@ struct ip_address_hash<4> namespace std { template <> -struct hash<::nano::endpoint> -{ - std::size_t operator() (::nano::endpoint const & endpoint_a) const - { - endpoint_hash ehash; - return ehash (endpoint_a); - } -}; +struct hash<::nano::endpoint>; #ifndef BOOST_ASIO_HAS_STD_HASH template <> -struct hash -{ - std::size_t operator() (boost::asio::ip::address const & ip_a) const - { - ip_address_hash ihash; - return ihash (ip_a); - } -}; +struct hash; #endif } namespace boost { template <> -struct hash<::nano::endpoint> -{ - std::size_t operator() (::nano::endpoint const & endpoint_a) const - { - std::hash<::nano::endpoint> hash; - return hash (endpoint_a); - } -}; +struct hash<::nano::endpoint>; template <> -struct hash -{ - std::size_t operator() (boost::asio::ip::address const & ip_a) const - { - std::hash hash; - return hash (ip_a); - } -}; +struct hash; } diff --git a/nano/node/endpoint_templ.hpp b/nano/node/endpoint_templ.hpp new file mode 100644 index 000000000..22d17e963 --- /dev/null +++ b/nano/node/endpoint_templ.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include +#include + +namespace std +{ +template <> +struct hash<::nano::endpoint> +{ + std::size_t operator() (::nano::endpoint const & endpoint_a) const + { + endpoint_hash ehash; + return ehash (endpoint_a); + } +}; + +#ifndef BOOST_ASIO_HAS_STD_HASH +template <> +struct hash +{ + std::size_t operator() (boost::asio::ip::address const & ip_a) const + { + ip_address_hash ihash; + return ihash (ip_a); + } +}; +#endif +} + +namespace boost +{ +template <> +struct hash<::nano::endpoint> +{ + std::size_t operator() (::nano::endpoint const & endpoint_a) const + { + std::hash<::nano::endpoint> hash; + return hash (endpoint_a); + } +}; + +template <> +struct hash +{ + std::size_t operator() (boost::asio::ip::address const & ip_a) const + { + std::hash hash; + return hash (ip_a); + } +}; +} diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 2b90c682e..d62c3d09b 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include #include #include #include diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 022c54d8e..c10f64199 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 9b315f538..dd47fa8b3 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -11,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/network.hpp b/nano/node/network.hpp index 0ab498ed2..d1130271d 100644 --- a/nano/node/network.hpp +++ b/nano/node/network.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index b8de6fff0..12e6069fc 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -11,10 +11,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include diff --git a/nano/node/peer_exclusion.hpp b/nano/node/peer_exclusion.hpp index 3100bfe09..e209d5e63 100644 --- a/nano/node/peer_exclusion.hpp +++ b/nano/node/peer_exclusion.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include #include #include diff --git a/nano/node/peer_history.hpp b/nano/node/peer_history.hpp index 15d13ffdd..6200446b5 100644 --- a/nano/node/peer_history.hpp +++ b/nano/node/peer_history.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -54,4 +54,4 @@ private: nano::condition_variable condition; std::thread thread; }; -} \ No newline at end of file +} diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 8465b7d2b..75faab069 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -1,7 +1,7 @@ #include #include -#include #include +#include #include #include #include diff --git a/nano/node/telemetry.hpp b/nano/node/telemetry.hpp index cb9c337a9..8e0fe8c31 100644 --- a/nano/node/telemetry.hpp +++ b/nano/node/telemetry.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index 6a4c6663e..8b7055c46 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/nano/node/transport/channel.hpp b/nano/node/transport/channel.hpp index 212dc1c37..8f860f58c 100644 --- a/nano/node/transport/channel.hpp +++ b/nano/node/transport/channel.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -140,4 +140,4 @@ private: public: // Logging virtual void operator() (nano::object_stream &) const; }; -} \ No newline at end of file +} diff --git a/nano/node/transport/message_deserializer.hpp b/nano/node/transport/message_deserializer.hpp index 4c4d62c22..ca8d923f3 100644 --- a/nano/node/transport/message_deserializer.hpp +++ b/nano/node/transport/message_deserializer.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/nano/node/transport/tcp_channels.hpp b/nano/node/transport/tcp_channels.hpp index 1b6f1e363..a4d4b2bc8 100644 --- a/nano/node/transport/tcp_channels.hpp +++ b/nano/node/transport/tcp_channels.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -170,4 +170,4 @@ private: mutable nano::random_generator rng; }; -} \ No newline at end of file +} diff --git a/nano/node/transport/tcp_listener.hpp b/nano/node/transport/tcp_listener.hpp index 55c63da64..c6c5730ce 100644 --- a/nano/node/transport/tcp_listener.hpp +++ b/nano/node/transport/tcp_listener.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -176,4 +176,4 @@ private: static std::string_view to_string (connection_type); static nano::transport::socket_endpoint to_socket_endpoint (connection_type); }; -} \ No newline at end of file +} diff --git a/nano/node/transport/tcp_server.hpp b/nano/node/transport/tcp_server.hpp index 96085ae8b..c4971464d 100644 --- a/nano/node/transport/tcp_server.hpp +++ b/nano/node/transport/tcp_server.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include diff --git a/nano/node/transport/transport.cpp b/nano/node/transport/transport.cpp index 4a90626f9..21f5fea04 100644 --- a/nano/node/transport/transport.cpp +++ b/nano/node/transport/transport.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -164,4 +164,4 @@ bool nano::transport::reserved_address (nano::endpoint const & endpoint_a, bool } } return result; -} \ No newline at end of file +} diff --git a/nano/node/transport/transport.hpp b/nano/node/transport/transport.hpp index 3065bbd04..5703a8c73 100644 --- a/nano/node/transport/transport.hpp +++ b/nano/node/transport/transport.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include @@ -24,4 +24,4 @@ bool is_same_subnetwork (boost::asio::ip::address const &, boost::asio::ip::addr // Unassigned, reserved, self bool reserved_address (nano::endpoint const &, bool allow_local_peers = false); -} \ No newline at end of file +} diff --git a/nano/node/websocket.hpp b/nano/node/websocket.hpp index 2a3895606..1a5eb0dbb 100644 --- a/nano/node/websocket.hpp +++ b/nano/node/websocket.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/nano/rpc_test/entry.cpp b/nano/rpc_test/entry.cpp index 806f07645..e16a3f4e5 100644 --- a/nano/rpc_test/entry.cpp +++ b/nano/rpc_test/entry.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include diff --git a/nano/test_common/network.hpp b/nano/test_common/network.hpp index 3bfcd22c3..d201fee17 100644 --- a/nano/test_common/network.hpp +++ b/nano/test_common/network.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include namespace nano diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 758a5c72e..b336139c9 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/test_common/telemetry.cpp b/nano/test_common/telemetry.cpp index db2465e07..a2aa36a3c 100644 --- a/nano/test_common/telemetry.cpp +++ b/nano/test_common/telemetry.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -61,4 +61,4 @@ bool nano::test::compare_telemetry (const nano::telemetry_data & data, const nan bool result = false; compare_telemetry_impl (data, node, result); return result; -} \ No newline at end of file +}