diff --git a/cmd/dev/backend_kv_server.cpp b/cmd/dev/backend_kv_server.cpp index 62ad347c86..2cfdc994da 100644 --- a/cmd/dev/backend_kv_server.cpp +++ b/cmd/dev/backend_kv_server.cpp @@ -113,11 +113,11 @@ int parse_command_line(int argc, char* argv[], CLI::App& app, StandaloneBackEndK return 0; } -std::shared_ptr make_sentry_client( +std::shared_ptr make_sentry_client( const NodeSettings& node_settings, rpc::ClientContextPool& context_pool, db::ROAccess db_access) { - std::shared_ptr sentry_client; + std::shared_ptr sentry_client; db::EthStatusDataProvider eth_status_data_provider{db_access, node_settings.chain_config.value()}; @@ -133,7 +133,7 @@ std::shared_ptr make_sentry_cli remote_sentry_client, eth_status_data_provider.to_factory_function()); } else { - std::vector> clients; + std::vector> clients; for (const auto& address_uri : node_settings.remote_sentry_addresses) { // remote client diff --git a/cmd/silkworm.cpp b/cmd/silkworm.cpp index 896b88a768..c618f5df88 100644 --- a/cmd/silkworm.cpp +++ b/cmd/silkworm.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -215,7 +215,7 @@ void parse_silkworm_command_line(CLI::App& cli, int argc, char* argv[], Silkworm class DummyServerCompletionQueue : public grpc::ServerCompletionQueue { }; -using SentryClientPtr = std::shared_ptr; +using SentryClientPtr = std::shared_ptr; using SentryServerPtr = std::shared_ptr; using SentryPtrPair = std::tuple; diff --git a/cmd/state-transition/state_transition.cpp b/cmd/state-transition/state_transition.cpp index a956386625..9e6f8c8d2c 100644 --- a/cmd/state-transition/state_transition.cpp +++ b/cmd/state-transition/state_transition.cpp @@ -25,13 +25,13 @@ #include "cmd/state-transition/expected_state.hpp" #include "silkworm/core/common/cast.hpp" +#include "silkworm/core/common/util.hpp" #include "silkworm/core/execution/execution.hpp" #include "silkworm/core/protocol/param.hpp" #include "silkworm/core/protocol/rule_set.hpp" #include "silkworm/core/rlp/encode_vector.hpp" #include "silkworm/core/state/in_memory_state.hpp" #include "silkworm/sentry/common/ecc_key_pair.hpp" -#include "third_party/ethash/include/ethash/keccak.hpp" namespace silkworm::cmd::state_transition { @@ -178,7 +178,7 @@ std::unique_ptr StateTransition::private_key_to_address(const std auto private_key_bytes = from_hex(private_key).value(); - sentry::common::EccKeyPair pair = sentry::common::EccKeyPair(private_key_bytes); + auto pair = sentry::EccKeyPair(private_key_bytes); uint8_t out[kAddressLength]; auto public_key_hash = keccak256(pair.public_key().serialized()); diff --git a/cmd/test/sentry_client_test.cpp b/cmd/test/sentry_client_test.cpp index c8a7b6f7a7..da0f6e9cf0 100644 --- a/cmd/test/sentry_client_test.cpp +++ b/cmd/test/sentry_client_test.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include @@ -32,7 +32,7 @@ using namespace silkworm; class DummyServerCompletionQueue : public grpc::ServerCompletionQueue { }; -boost::asio::awaitable run(sentry::api::api_common::SentryClient& client) { +boost::asio::awaitable run(sentry::api::SentryClient& client) { auto service = co_await client.service(); try { auto eth_version = co_await service->handshake(); diff --git a/silkworm/node/backend/ethereum_backend.cpp b/silkworm/node/backend/ethereum_backend.cpp index a1679f9655..a1f0846772 100644 --- a/silkworm/node/backend/ethereum_backend.cpp +++ b/silkworm/node/backend/ethereum_backend.cpp @@ -21,14 +21,14 @@ namespace silkworm { EthereumBackEnd::EthereumBackEnd( const NodeSettings& node_settings, mdbx::env* chaindata_env, - std::shared_ptr sentry_client) + std::shared_ptr sentry_client) : EthereumBackEnd(node_settings, chaindata_env, std::move(sentry_client), std::make_unique()) { } EthereumBackEnd::EthereumBackEnd( const NodeSettings& node_settings, mdbx::env* chaindata_env, - std::shared_ptr sentry_client, + std::shared_ptr sentry_client, std::unique_ptr state_change_collection) : node_settings_(node_settings), chaindata_env_(chaindata_env), diff --git a/silkworm/node/backend/ethereum_backend.hpp b/silkworm/node/backend/ethereum_backend.hpp index 4cd4c9b090..99529b218f 100644 --- a/silkworm/node/backend/ethereum_backend.hpp +++ b/silkworm/node/backend/ethereum_backend.hpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace silkworm { @@ -36,7 +36,7 @@ class EthereumBackEnd { explicit EthereumBackEnd( const NodeSettings& node_settings, mdbx::env* chaindata_env, - std::shared_ptr sentry_client); + std::shared_ptr sentry_client); ~EthereumBackEnd(); EthereumBackEnd(const EthereumBackEnd&) = delete; @@ -46,7 +46,7 @@ class EthereumBackEnd { [[nodiscard]] const std::string& node_name() const noexcept { return node_name_; } [[nodiscard]] std::optional chain_id() const noexcept { return chain_id_; } [[nodiscard]] std::optional etherbase() const noexcept { return node_settings_.etherbase; } - [[nodiscard]] std::shared_ptr sentry_client() const noexcept { return sentry_client_; } + [[nodiscard]] std::shared_ptr sentry_client() const noexcept { return sentry_client_; } [[nodiscard]] StateChangeCollection* state_change_source() const noexcept { return state_change_collection_.get(); } void set_node_name(const std::string& node_name) noexcept; @@ -58,7 +58,7 @@ class EthereumBackEnd { EthereumBackEnd( const NodeSettings& node_settings, mdbx::env* chaindata_env, - std::shared_ptr sentry_client, + std::shared_ptr sentry_client, std::unique_ptr state_change_collection); private: @@ -66,7 +66,7 @@ class EthereumBackEnd { mdbx::env* chaindata_env_; std::string node_name_{kDefaultNodeName}; std::optional chain_id_{std::nullopt}; - std::shared_ptr sentry_client_; + std::shared_ptr sentry_client_; std::unique_ptr state_change_collection_; }; diff --git a/silkworm/node/backend/ethereum_backend_test.cpp b/silkworm/node/backend/ethereum_backend_test.cpp index 64db34b264..749bef5e33 100644 --- a/silkworm/node/backend/ethereum_backend_test.cpp +++ b/silkworm/node/backend/ethereum_backend_test.cpp @@ -38,7 +38,7 @@ TEST_CASE("EthereumBackEnd", "[silkworm][backend][ethereum_backend]") { NodeSettings node_settings; - std::shared_ptr null_sentry_client; + std::shared_ptr null_sentry_client; SECTION("EthereumBackEnd::EthereumBackEnd", "[silkworm][backend][ethereum_backend]") { EthereumBackEnd backend{node_settings, &database_env, null_sentry_client}; diff --git a/silkworm/node/backend/remote/backend_kv_server_test.cpp b/silkworm/node/backend/remote/backend_kv_server_test.cpp index c9365c61fe..a5bdf4b4dc 100644 --- a/silkworm/node/backend/remote/backend_kv_server_test.cpp +++ b/silkworm/node/backend/remote/backend_kv_server_test.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include using namespace std::chrono_literals; @@ -207,9 +207,9 @@ constexpr const char* kTestSentryNodeClientId{"MockSentryClient"}; class MockSentryClient : public std::enable_shared_from_this, - public silkworm::sentry::api::api_common::SentryClient, - public silkworm::sentry::api::api_common::Service { - boost::asio::awaitable> service() override { + public silkworm::sentry::api::SentryClient, + public silkworm::sentry::api::Service { + boost::asio::awaitable> service() override { co_return shared_from_this(); } [[nodiscard]] bool is_ready() override { return true; } @@ -227,8 +227,8 @@ class MockSentryClient const uint16_t port = 50555; const std::string node_url_str = std::string("enode://") + kTestSentryNodeId + "@" + ip_str + ":" + std::to_string(port); - silkworm::sentry::api::api_common::NodeInfo info = { - silkworm::sentry::common::EnodeUrl{node_url_str}, + silkworm::sentry::api::NodeInfo info = { + silkworm::sentry::EnodeUrl{node_url_str}, kTestSentryNodeClientId, boost::asio::ip::tcp::endpoint{boost::asio::ip::make_address(ip_str), port}, port, @@ -236,40 +236,40 @@ class MockSentryClient co_return NodeInfos{info}; } - boost::asio::awaitable send_message_by_id(silkworm::sentry::common::Message /*message*/, silkworm::sentry::common::EccPublicKey /*public_key*/) override { + boost::asio::awaitable send_message_by_id(silkworm::sentry::Message /*message*/, silkworm::sentry::EccPublicKey /*public_key*/) override { throw std::runtime_error("not implemented"); } - boost::asio::awaitable send_message_to_random_peers(silkworm::sentry::common::Message /*message*/, size_t /*max_peers*/) override { + boost::asio::awaitable send_message_to_random_peers(silkworm::sentry::Message /*message*/, size_t /*max_peers*/) override { throw std::runtime_error("not implemented"); } - boost::asio::awaitable send_message_to_all(silkworm::sentry::common::Message /*message*/) override { + boost::asio::awaitable send_message_to_all(silkworm::sentry::Message /*message*/) override { throw std::runtime_error("not implemented"); } - boost::asio::awaitable send_message_by_min_block(silkworm::sentry::common::Message /*message*/, size_t /*max_peers*/) override { + boost::asio::awaitable send_message_by_min_block(silkworm::sentry::Message /*message*/, size_t /*max_peers*/) override { throw std::runtime_error("not implemented"); } - boost::asio::awaitable peer_min_block(silkworm::sentry::common::EccPublicKey /*public_key*/) override { + boost::asio::awaitable peer_min_block(silkworm::sentry::EccPublicKey /*public_key*/) override { throw std::runtime_error("not implemented"); } boost::asio::awaitable messages( - silkworm::sentry::api::api_common::MessageIdSet /*message_id_filter*/, - std::function(silkworm::sentry::api::api_common::MessageFromPeer)> /*consumer*/) override { + silkworm::sentry::api::MessageIdSet /*message_id_filter*/, + std::function(silkworm::sentry::api::MessageFromPeer)> /*consumer*/) override { throw std::runtime_error("not implemented"); } - boost::asio::awaitable peers() override { + boost::asio::awaitable peers() override { throw std::runtime_error("not implemented"); } boost::asio::awaitable peer_count() override { co_return kTestSentryPeerCount; } - boost::asio::awaitable> peer_by_id(silkworm::sentry::common::EccPublicKey /*public_key*/) override { + boost::asio::awaitable> peer_by_id(silkworm::sentry::EccPublicKey /*public_key*/) override { throw std::runtime_error("not implemented"); } - boost::asio::awaitable penalize_peer(silkworm::sentry::common::EccPublicKey /*public_key*/) override { + boost::asio::awaitable penalize_peer(silkworm::sentry::EccPublicKey /*public_key*/) override { throw std::runtime_error("not implemented"); } - boost::asio::awaitable peer_events(std::function(silkworm::sentry::api::api_common::PeerEvent)> /*consumer*/) override { + boost::asio::awaitable peer_events(std::function(silkworm::sentry::api::PeerEvent)> /*consumer*/) override { throw std::runtime_error("not implemented"); } }; diff --git a/silkworm/node/node.cpp b/silkworm/node/node.cpp index d4762d6f35..daf0d885e1 100644 --- a/silkworm/node/node.cpp +++ b/silkworm/node/node.cpp @@ -32,7 +32,7 @@ namespace silkworm::node { constexpr uint64_t kMaxFileDescriptors{10'240}; -using SentryClientPtr = std::shared_ptr; +using SentryClientPtr = std::shared_ptr; class NodeImpl final { public: @@ -42,7 +42,7 @@ class NodeImpl final { NodeImpl& operator=(const NodeImpl&) = delete; execution::LocalClient& execution_local_client() { return execution_local_client_; } - std::shared_ptr sentry_client() { return sentry_client_; } + std::shared_ptr sentry_client() { return sentry_client_; } void setup(); diff --git a/silkworm/node/node.hpp b/silkworm/node/node.hpp index 9a0714585b..df4ab4053c 100644 --- a/silkworm/node/node.hpp +++ b/silkworm/node/node.hpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include namespace silkworm::node { @@ -34,7 +34,7 @@ class NodeImpl; class Node { public: - Node(Settings&, std::shared_ptr, mdbx::env&); + Node(Settings&, std::shared_ptr, mdbx::env&); ~Node(); Node(const Node&) = delete; diff --git a/silkworm/sentry/api/api_common/message_from_peer.hpp b/silkworm/sentry/api/common/message_from_peer.hpp similarity index 78% rename from silkworm/sentry/api/api_common/message_from_peer.hpp rename to silkworm/sentry/api/common/message_from_peer.hpp index ff91b4b1d0..fb395c451e 100644 --- a/silkworm/sentry/api/api_common/message_from_peer.hpp +++ b/silkworm/sentry/api/common/message_from_peer.hpp @@ -19,11 +19,11 @@ #include #include -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { struct MessageFromPeer { - sentry::common::Message message; - std::optional peer_public_key; + sentry::Message message; + std::optional peer_public_key; }; -} // namespace silkworm::sentry::api::api_common +} // namespace silkworm::sentry::api diff --git a/silkworm/sentry/api/api_common/message_id_set.hpp b/silkworm/sentry/api/common/message_id_set.hpp similarity index 87% rename from silkworm/sentry/api/api_common/message_id_set.hpp rename to silkworm/sentry/api/common/message_id_set.hpp index 61bdd47024..0e6ee4a7eb 100644 --- a/silkworm/sentry/api/api_common/message_id_set.hpp +++ b/silkworm/sentry/api/common/message_id_set.hpp @@ -18,8 +18,8 @@ #include -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { using MessageIdSet = std::set; -} // namespace silkworm::sentry::api::api_common +} // namespace silkworm::sentry::api diff --git a/silkworm/sentry/api/api_common/node_info.hpp b/silkworm/sentry/api/common/node_info.hpp similarity index 86% rename from silkworm/sentry/api/api_common/node_info.hpp rename to silkworm/sentry/api/common/node_info.hpp index 3842819e2c..d19952459a 100644 --- a/silkworm/sentry/api/api_common/node_info.hpp +++ b/silkworm/sentry/api/common/node_info.hpp @@ -22,13 +22,13 @@ #include -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { struct NodeInfo { - sentry::common::EnodeUrl node_url; + sentry::EnodeUrl node_url; std::string client_id; boost::asio::ip::tcp::endpoint rlpx_server_listen_endpoint; uint16_t rlpx_server_port; }; -} // namespace silkworm::sentry::api::api_common +} // namespace silkworm::sentry::api diff --git a/silkworm/sentry/api/api_common/peer_event.hpp b/silkworm/sentry/api/common/peer_event.hpp similarity index 83% rename from silkworm/sentry/api/api_common/peer_event.hpp rename to silkworm/sentry/api/common/peer_event.hpp index f0e60c3819..1450443340 100644 --- a/silkworm/sentry/api/api_common/peer_event.hpp +++ b/silkworm/sentry/api/common/peer_event.hpp @@ -20,7 +20,7 @@ #include -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { enum class PeerEventId { kAdded, @@ -28,8 +28,8 @@ enum class PeerEventId { }; struct PeerEvent { - std::optional peer_public_key; + std::optional peer_public_key; PeerEventId event_id; }; -} // namespace silkworm::sentry::api::api_common \ No newline at end of file +} // namespace silkworm::sentry::api \ No newline at end of file diff --git a/silkworm/sentry/api/api_common/peer_filter.hpp b/silkworm/sentry/api/common/peer_filter.hpp similarity index 78% rename from silkworm/sentry/api/api_common/peer_filter.hpp rename to silkworm/sentry/api/common/peer_filter.hpp index dccfd53d3a..66554e95da 100644 --- a/silkworm/sentry/api/api_common/peer_filter.hpp +++ b/silkworm/sentry/api/common/peer_filter.hpp @@ -20,19 +20,19 @@ #include -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { struct PeerFilter { std::optional max_peers; - std::optional peer_public_key; + std::optional peer_public_key; static PeerFilter with_max_peers(size_t max_peers) { return {{max_peers}, std::nullopt}; } - static PeerFilter with_peer_public_key(sentry::common::EccPublicKey public_key) { + static PeerFilter with_peer_public_key(sentry::EccPublicKey public_key) { return {std::nullopt, {std::move(public_key)}}; } }; -} // namespace silkworm::sentry::api::api_common +} // namespace silkworm::sentry::api diff --git a/silkworm/sentry/api/api_common/peer_info.hpp b/silkworm/sentry/api/common/peer_info.hpp similarity index 88% rename from silkworm/sentry/api/api_common/peer_info.hpp rename to silkworm/sentry/api/common/peer_info.hpp index b037448bdf..e8c9a5ac25 100644 --- a/silkworm/sentry/api/api_common/peer_info.hpp +++ b/silkworm/sentry/api/common/peer_info.hpp @@ -23,10 +23,10 @@ #include -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { struct PeerInfo { - sentry::common::EnodeUrl url; + sentry::EnodeUrl url; boost::asio::ip::tcp::endpoint local_endpoint; boost::asio::ip::tcp::endpoint remote_endpoint; bool is_inbound; @@ -37,4 +37,4 @@ struct PeerInfo { using PeerInfos = std::vector; -} // namespace silkworm::sentry::api::api_common +} // namespace silkworm::sentry::api diff --git a/silkworm/sentry/api/api_common/sentry_client.hpp b/silkworm/sentry/api/common/sentry_client.hpp similarity index 92% rename from silkworm/sentry/api/api_common/sentry_client.hpp rename to silkworm/sentry/api/common/sentry_client.hpp index 5083d3a0a9..e00cf31d98 100644 --- a/silkworm/sentry/api/api_common/sentry_client.hpp +++ b/silkworm/sentry/api/common/sentry_client.hpp @@ -23,7 +23,7 @@ #include "service.hpp" -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { struct SentryClient { virtual ~SentryClient() = default; @@ -36,4 +36,4 @@ struct SentryClient { virtual Task reconnect() = 0; }; -} // namespace silkworm::sentry::api::api_common +} // namespace silkworm::sentry::api diff --git a/silkworm/sentry/api/api_common/service.hpp b/silkworm/sentry/api/common/service.hpp similarity index 76% rename from silkworm/sentry/api/api_common/service.hpp rename to silkworm/sentry/api/common/service.hpp index 308b8931e7..439375f2d6 100644 --- a/silkworm/sentry/api/api_common/service.hpp +++ b/silkworm/sentry/api/common/service.hpp @@ -33,7 +33,7 @@ #include "peer_event.hpp" #include "peer_info.hpp" -namespace silkworm::sentry::api::api_common { +namespace silkworm::sentry::api { struct Service { virtual ~Service() = default; @@ -49,22 +49,22 @@ struct Service { // rpc NodeInfo(google.protobuf.Empty) returns(types.NodeInfoReply); virtual Task node_infos() = 0; - using PeerKeys = std::vector; + using PeerKeys = std::vector; // rpc SendMessageById(SendMessageByIdRequest) returns (SentPeers); - virtual Task send_message_by_id(common::Message message, common::EccPublicKey public_key) = 0; + virtual Task send_message_by_id(Message message, EccPublicKey public_key) = 0; // rpc SendMessageToRandomPeers(SendMessageToRandomPeersRequest) returns (SentPeers); - virtual Task send_message_to_random_peers(common::Message message, size_t max_peers) = 0; + virtual Task send_message_to_random_peers(Message message, size_t max_peers) = 0; // rpc SendMessageToAll(OutboundMessageData) returns (SentPeers); - virtual Task send_message_to_all(common::Message message) = 0; + virtual Task send_message_to_all(Message message) = 0; // rpc SendMessageByMinBlock(SendMessageByMinBlockRequest) returns (SentPeers); - virtual Task send_message_by_min_block(common::Message message, size_t max_peers) = 0; + virtual Task send_message_by_min_block(Message message, size_t max_peers) = 0; // rpc PeerMinBlock(PeerMinBlockRequest) returns (google.protobuf.Empty); - virtual Task peer_min_block(common::EccPublicKey public_key) = 0; + virtual Task peer_min_block(EccPublicKey public_key) = 0; // rpc Messages(MessagesRequest) returns (stream InboundMessage); virtual Task messages( @@ -78,13 +78,13 @@ struct Service { virtual Task peer_count() = 0; // rpc PeerById(PeerByIdRequest) returns (PeerByIdReply); - virtual Task> peer_by_id(common::EccPublicKey public_key) = 0; + virtual Task> peer_by_id(EccPublicKey public_key) = 0; // rpc PenalizePeer(PenalizePeerRequest) returns (google.protobuf.Empty); - virtual Task penalize_peer(common::EccPublicKey public_key) = 0; + virtual Task penalize_peer(EccPublicKey public_key) = 0; // rpc PeerEvents(PeerEventsRequest) returns (stream PeerEvent); virtual Task peer_events(std::function(PeerEvent)> consumer) = 0; }; -} // namespace silkworm::sentry::api::api_common +} // namespace silkworm::sentry::api diff --git a/silkworm/sentry/api/router/direct_service.cpp b/silkworm/sentry/api/router/direct_service.cpp index 5c0d7f6253..0c9aa2bad7 100644 --- a/silkworm/sentry/api/router/direct_service.cpp +++ b/silkworm/sentry/api/router/direct_service.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include "messages_call.hpp" #include "peer_call.hpp" @@ -42,44 +42,44 @@ Task DirectService::handshake() { co_return router_.eth_version; } -Task DirectService::node_infos() { - co_return api_common::Service::NodeInfos{router_.node_info_provider()}; +Task DirectService::node_infos() { + co_return Service::NodeInfos{router_.node_info_provider()}; } -static Task do_send_message_call( +static Task do_send_message_call( const ServiceRouter& router, - common::Message message, - api_common::PeerFilter peer_filter) { + Message message, + PeerFilter peer_filter) { auto executor = co_await this_coro::executor; SendMessageCall call{std::move(message), std::move(peer_filter), executor}; co_await router.send_message_channel.send(call); co_return (co_await call.result()); } -Task DirectService::send_message_by_id(common::Message message, common::EccPublicKey public_key) { - co_return (co_await do_send_message_call(router_, std::move(message), api_common::PeerFilter::with_peer_public_key(std::move(public_key)))); +Task DirectService::send_message_by_id(Message message, EccPublicKey public_key) { + co_return (co_await do_send_message_call(router_, std::move(message), PeerFilter::with_peer_public_key(std::move(public_key)))); } -Task DirectService::send_message_to_random_peers(common::Message message, size_t max_peers) { - co_return (co_await do_send_message_call(router_, std::move(message), api_common::PeerFilter::with_max_peers(max_peers))); +Task DirectService::send_message_to_random_peers(Message message, size_t max_peers) { + co_return (co_await do_send_message_call(router_, std::move(message), PeerFilter::with_max_peers(max_peers))); } -Task DirectService::send_message_to_all(common::Message message) { - co_return (co_await do_send_message_call(router_, std::move(message), api::api_common::PeerFilter{})); +Task DirectService::send_message_to_all(Message message) { + co_return (co_await do_send_message_call(router_, std::move(message), api::PeerFilter{})); } -Task DirectService::send_message_by_min_block(common::Message message, size_t max_peers) { - co_return (co_await do_send_message_call(router_, std::move(message), api_common::PeerFilter::with_max_peers(max_peers))); +Task DirectService::send_message_by_min_block(Message message, size_t max_peers) { + co_return (co_await do_send_message_call(router_, std::move(message), PeerFilter::with_max_peers(max_peers))); } -Task DirectService::peer_min_block(common::EccPublicKey /*public_key*/) { +Task DirectService::peer_min_block(EccPublicKey /*public_key*/) { // TODO: implement co_return; } Task DirectService::messages( - api_common::MessageIdSet message_id_filter, - std::function(api_common::MessageFromPeer)> consumer) { + MessageIdSet message_id_filter, + std::function(MessageFromPeer)> consumer) { auto executor = co_await this_coro::executor; MessagesCall call{std::move(message_id_filter), executor}; @@ -96,9 +96,9 @@ Task DirectService::messages( } } -Task DirectService::peers() { +Task DirectService::peers() { auto executor = co_await this_coro::executor; - auto call = std::make_shared>(executor); + auto call = std::make_shared>(executor); auto call_future = call->get_future(); co_await router_.peers_calls_channel.send(call); co_return (co_await call_future.get_async()); @@ -112,7 +112,7 @@ Task DirectService::peer_count() { co_return (co_await call_future.get_async()); } -Task> DirectService::peer_by_id(common::EccPublicKey public_key) { +Task> DirectService::peer_by_id(EccPublicKey public_key) { auto executor = co_await this_coro::executor; PeerCall call{std::move(public_key), executor}; auto call_future = call.result_promise->get_future(); @@ -120,12 +120,12 @@ Task> DirectService::peer_by_id(common::EccP co_return (co_await call_future.get_async()); } -Task DirectService::penalize_peer(common::EccPublicKey public_key) { +Task DirectService::penalize_peer(EccPublicKey public_key) { co_await router_.peer_penalize_calls_channel.send({std::move(public_key)}); } Task DirectService::peer_events( - std::function(api_common::PeerEvent)> consumer) { + std::function(PeerEvent)> consumer) { auto executor = co_await this_coro::executor; PeerEventsCall call{executor}; auto call_future = call.result_promise->get_future(); diff --git a/silkworm/sentry/api/router/direct_service.hpp b/silkworm/sentry/api/router/direct_service.hpp index ed51b65ccf..14df253abc 100644 --- a/silkworm/sentry/api/router/direct_service.hpp +++ b/silkworm/sentry/api/router/direct_service.hpp @@ -16,13 +16,13 @@ #pragma once -#include +#include #include "service_router.hpp" namespace silkworm::sentry::api::router { -class DirectService : public api_common::Service { +class DirectService : public Service { public: explicit DirectService(ServiceRouter router) : router_(std::move(router)) {} @@ -32,20 +32,20 @@ class DirectService : public api_common::Service { Task handshake() override; Task node_infos() override; - Task send_message_by_id(common::Message message, common::EccPublicKey public_key) override; - Task send_message_to_random_peers(common::Message message, size_t max_peers) override; - Task send_message_to_all(common::Message message) override; - Task send_message_by_min_block(common::Message message, size_t max_peers) override; - Task peer_min_block(common::EccPublicKey public_key) override; + Task send_message_by_id(Message message, EccPublicKey public_key) override; + Task send_message_to_random_peers(Message message, size_t max_peers) override; + Task send_message_to_all(Message message) override; + Task send_message_by_min_block(Message message, size_t max_peers) override; + Task peer_min_block(EccPublicKey public_key) override; Task messages( - api_common::MessageIdSet message_id_filter, - std::function(api_common::MessageFromPeer)> consumer) override; + MessageIdSet message_id_filter, + std::function(MessageFromPeer)> consumer) override; - Task peers() override; + Task peers() override; Task peer_count() override; - Task> peer_by_id(common::EccPublicKey public_key) override; - Task penalize_peer(common::EccPublicKey public_key) override; - Task peer_events(std::function(api_common::PeerEvent)> consumer) override; + Task> peer_by_id(EccPublicKey public_key) override; + Task penalize_peer(EccPublicKey public_key) override; + Task peer_events(std::function(PeerEvent)> consumer) override; private: ServiceRouter router_; diff --git a/silkworm/sentry/api/router/messages_call.hpp b/silkworm/sentry/api/router/messages_call.hpp index 5a79899653..f05b4f70e0 100644 --- a/silkworm/sentry/api/router/messages_call.hpp +++ b/silkworm/sentry/api/router/messages_call.hpp @@ -27,17 +27,17 @@ #include #include #include -#include -#include +#include +#include namespace silkworm::sentry::api::router { class MessagesCall final { public: - using TResult = std::shared_ptr>; + using TResult = std::shared_ptr>; MessagesCall( - api_common::MessageIdSet message_id_filter, + MessageIdSet message_id_filter, boost::asio::any_io_executor& executor) : message_id_filter_(std::move(message_id_filter)), result_promise_(std::make_shared>(executor)), @@ -45,7 +45,7 @@ class MessagesCall final { MessagesCall() = default; - [[nodiscard]] const api_common::MessageIdSet& message_id_filter() const { return message_id_filter_; } + [[nodiscard]] const MessageIdSet& message_id_filter() const { return message_id_filter_; } Task result() { auto future = result_promise_->get_future(); @@ -61,7 +61,7 @@ class MessagesCall final { } private: - api_common::MessageIdSet message_id_filter_; + MessageIdSet message_id_filter_; std::shared_ptr> result_promise_; std::shared_ptr unsubscribe_signal_; }; diff --git a/silkworm/sentry/api/router/peer_call.hpp b/silkworm/sentry/api/router/peer_call.hpp index 5e63e961be..8d1b9ef3ad 100644 --- a/silkworm/sentry/api/router/peer_call.hpp +++ b/silkworm/sentry/api/router/peer_call.hpp @@ -22,22 +22,22 @@ #include #include -#include +#include #include namespace silkworm::sentry::api::router { struct PeerCall { - std::optional peer_public_key; - std::shared_ptr>> result_promise; + std::optional peer_public_key; + std::shared_ptr>> result_promise; PeerCall() = default; PeerCall( - sentry::common::EccPublicKey peer_public_key1, + sentry::EccPublicKey peer_public_key1, boost::asio::any_io_executor& executor) : peer_public_key(std::move(peer_public_key1)), - result_promise(std::make_shared>>(executor)) {} + result_promise(std::make_shared>>(executor)) {} }; } // namespace silkworm::sentry::api::router diff --git a/silkworm/sentry/api/router/peer_events_call.hpp b/silkworm/sentry/api/router/peer_events_call.hpp index 0a4a3dc500..a17104d004 100644 --- a/silkworm/sentry/api/router/peer_events_call.hpp +++ b/silkworm/sentry/api/router/peer_events_call.hpp @@ -23,12 +23,12 @@ #include #include #include -#include +#include namespace silkworm::sentry::api::router { struct PeerEventsCall { - using TResult = std::shared_ptr>; + using TResult = std::shared_ptr>; std::shared_ptr> result_promise; std::shared_ptr unsubscribe_signal; diff --git a/silkworm/sentry/api/router/send_message_call.hpp b/silkworm/sentry/api/router/send_message_call.hpp index 5fdc874198..391c07af2e 100644 --- a/silkworm/sentry/api/router/send_message_call.hpp +++ b/silkworm/sentry/api/router/send_message_call.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -32,11 +32,11 @@ namespace silkworm::sentry::api::router { class SendMessageCall final { public: - using PeerKeys = std::vector; + using PeerKeys = std::vector; SendMessageCall( - sentry::common::Message message, - api_common::PeerFilter peer_filter, + sentry::Message message, + PeerFilter peer_filter, boost::asio::any_io_executor& executor) : message_(std::move(message)), peer_filter_(std::move(peer_filter)), @@ -44,8 +44,8 @@ class SendMessageCall final { SendMessageCall() = default; - [[nodiscard]] const sentry::common::Message& message() const { return message_; } - [[nodiscard]] const api_common::PeerFilter& peer_filter() const { return peer_filter_; } + [[nodiscard]] const sentry::Message& message() const { return message_; } + [[nodiscard]] const PeerFilter& peer_filter() const { return peer_filter_; } Task result() { auto future = result_promise_->get_future(); @@ -57,8 +57,8 @@ class SendMessageCall final { } private: - sentry::common::Message message_; - api_common::PeerFilter peer_filter_; + sentry::Message message_; + PeerFilter peer_filter_; std::shared_ptr> result_promise_; }; diff --git a/silkworm/sentry/api/router/service_router.hpp b/silkworm/sentry/api/router/service_router.hpp index 9aeb7d6043..58b8080be1 100644 --- a/silkworm/sentry/api/router/service_router.hpp +++ b/silkworm/sentry/api/router/service_router.hpp @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -45,12 +45,12 @@ struct ServiceRouter { Channel& message_calls_channel; Channel>>& peer_count_calls_channel; - Channel>>& peers_calls_channel; + Channel>>& peers_calls_channel; Channel& peer_calls_channel; - Channel>& peer_penalize_calls_channel; + Channel>& peer_penalize_calls_channel; Channel& peer_events_calls_channel; - std::function node_info_provider; + std::function node_info_provider; }; } // namespace silkworm::sentry::api::router diff --git a/silkworm/sentry/common/atomic_value.hpp b/silkworm/sentry/common/atomic_value.hpp index 79c1e0420a..fd88372f0a 100644 --- a/silkworm/sentry/common/atomic_value.hpp +++ b/silkworm/sentry/common/atomic_value.hpp @@ -19,7 +19,7 @@ #include #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { template class AtomicValue { @@ -45,4 +45,4 @@ class AtomicValue { std::mutex mutex_; }; -} // namespace silkworm::sentry::common \ No newline at end of file +} // namespace silkworm::sentry \ No newline at end of file diff --git a/silkworm/sentry/common/crypto/ecdsa_signature.cpp b/silkworm/sentry/common/crypto/ecdsa_signature.cpp index 8284ee198d..fc9ef6c43b 100644 --- a/silkworm/sentry/common/crypto/ecdsa_signature.cpp +++ b/silkworm/sentry/common/crypto/ecdsa_signature.cpp @@ -20,7 +20,7 @@ #include -namespace silkworm::sentry::common::crypto::ecdsa_signature { +namespace silkworm::sentry::crypto::ecdsa_signature { Bytes sign(ByteView data, ByteView private_key) { SecP256K1Context ctx{/* allow_verify = */ false, /* allow_sign = */ true}; @@ -35,7 +35,7 @@ Bytes sign(ByteView data, ByteView private_key) { return signature_data; } -common::EccPublicKey recover_and_verify(ByteView data, ByteView signature_and_recovery_id) { +EccPublicKey recover_and_verify(ByteView data, ByteView signature_and_recovery_id) { if (signature_and_recovery_id.empty()) { throw std::runtime_error("rlpx::auth::recover_and_verify: AuthMessage signature is empty"); } @@ -54,7 +54,7 @@ common::EccPublicKey recover_and_verify(ByteView data, ByteView signature_and_re if (!ok) { throw std::runtime_error("rlpx::auth::recover_and_verify: failed to recover a public key from an AuthMessage signature"); } - return common::EccPublicKey{Bytes{public_key.data, sizeof(public_key.data)}}; + return EccPublicKey{Bytes{public_key.data, sizeof(public_key.data)}}; } -} // namespace silkworm::sentry::common::crypto::ecdsa_signature +} // namespace silkworm::sentry::crypto::ecdsa_signature diff --git a/silkworm/sentry/common/crypto/ecdsa_signature.hpp b/silkworm/sentry/common/crypto/ecdsa_signature.hpp index 735b9bd286..aa47cd99e7 100644 --- a/silkworm/sentry/common/crypto/ecdsa_signature.hpp +++ b/silkworm/sentry/common/crypto/ecdsa_signature.hpp @@ -19,9 +19,9 @@ #include #include -namespace silkworm::sentry::common::crypto::ecdsa_signature { +namespace silkworm::sentry::crypto::ecdsa_signature { Bytes sign(ByteView data, ByteView private_key); -common::EccPublicKey recover_and_verify(ByteView data, ByteView signature_and_recovery_id); +EccPublicKey recover_and_verify(ByteView data, ByteView signature_and_recovery_id); -} // namespace silkworm::sentry::common::crypto::ecdsa_signature +} // namespace silkworm::sentry::crypto::ecdsa_signature diff --git a/silkworm/sentry/common/ecc_key_pair.cpp b/silkworm/sentry/common/ecc_key_pair.cpp index 57cd8e35ed..272c7eb7d7 100644 --- a/silkworm/sentry/common/ecc_key_pair.cpp +++ b/silkworm/sentry/common/ecc_key_pair.cpp @@ -23,12 +23,12 @@ #include "random.hpp" -namespace silkworm::sentry::common { +namespace silkworm::sentry { EccKeyPair::EccKeyPair() { SecP256K1Context ctx; do { - private_key_ = common::random_bytes(32); + private_key_ = random_bytes(32); } while (!ctx.verify_private_key_data(private_key_)); } @@ -54,4 +54,4 @@ std::string EccKeyPair::private_key_hex() const { return ::silkworm::to_hex(private_key_); } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/ecc_key_pair.hpp b/silkworm/sentry/common/ecc_key_pair.hpp index b68704d951..a6236dd651 100644 --- a/silkworm/sentry/common/ecc_key_pair.hpp +++ b/silkworm/sentry/common/ecc_key_pair.hpp @@ -22,7 +22,7 @@ #include "ecc_public_key.hpp" -namespace silkworm::sentry::common { +namespace silkworm::sentry { class EccKeyPair { public: @@ -39,4 +39,4 @@ class EccKeyPair { Bytes private_key_; }; -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/ecc_key_pair_test.cpp b/silkworm/sentry/common/ecc_key_pair_test.cpp index fc0354c727..2e64b03eb5 100644 --- a/silkworm/sentry/common/ecc_key_pair_test.cpp +++ b/silkworm/sentry/common/ecc_key_pair_test.cpp @@ -20,7 +20,7 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { TEST_CASE("EccKeyPair.public_key_hex") { CHECK( @@ -33,4 +33,4 @@ TEST_CASE("EccKeyPair.public_key_hex") { .hex() == "24bfa2cdce7c6a41184fa0809ad8d76969b7280952e9aa46179d90cfbab90f7d2b004928f0364389a1aa8d5166281f2ff7568493c1f719e8f6148ef8cf8af42d"); } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/ecc_public_key.cpp b/silkworm/sentry/common/ecc_public_key.cpp index 8df939994d..8b19e29513 100644 --- a/silkworm/sentry/common/ecc_public_key.cpp +++ b/silkworm/sentry/common/ecc_public_key.cpp @@ -21,7 +21,7 @@ #include #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { Bytes EccPublicKey::serialized_std() const { auto& data = data_; @@ -72,4 +72,4 @@ bool operator<(const EccPublicKey& lhs, const EccPublicKey& rhs) { return lhs.data() < rhs.data(); } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/ecc_public_key.hpp b/silkworm/sentry/common/ecc_public_key.hpp index c0fe73f856..ea5da7d157 100644 --- a/silkworm/sentry/common/ecc_public_key.hpp +++ b/silkworm/sentry/common/ecc_public_key.hpp @@ -22,7 +22,7 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { class EccPublicKey { public: @@ -48,14 +48,14 @@ class EccPublicKey { //! for using EccPublicKey as a key of std::map bool operator<(const EccPublicKey& lhs, const EccPublicKey& rhs); -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry namespace std { //! for using EccPublicKey as a key of std::unordered_map template <> -struct hash { - size_t operator()(const silkworm::sentry::common::EccPublicKey& public_key) const noexcept { +struct hash { + size_t operator()(const silkworm::sentry::EccPublicKey& public_key) const noexcept { silkworm::ByteView data = public_key.data(); std::string_view data_str{reinterpret_cast(data.data()), data.size()}; return std::hash{}(data_str); diff --git a/silkworm/sentry/common/enode_url.cpp b/silkworm/sentry/common/enode_url.cpp index e3ea084952..a3600b6131 100644 --- a/silkworm/sentry/common/enode_url.cpp +++ b/silkworm/sentry/common/enode_url.cpp @@ -22,7 +22,7 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { using namespace std; @@ -44,7 +44,7 @@ EnodeUrl::EnodeUrl(const string& url_str) auto port = boost::lexical_cast(port_str); - public_key_ = common::EccPublicKey::deserialize_hex(pub_key_hex); + public_key_ = EccPublicKey::deserialize_hex(pub_key_hex); ip_ = ip; port_ = port; } @@ -62,4 +62,4 @@ bool EnodeUrl::operator<(const EnodeUrl& other) const { return to_string() < other.to_string(); } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/enode_url.hpp b/silkworm/sentry/common/enode_url.hpp index fc0809df08..d872dd22c9 100644 --- a/silkworm/sentry/common/enode_url.hpp +++ b/silkworm/sentry/common/enode_url.hpp @@ -22,18 +22,18 @@ #include "ecc_public_key.hpp" -namespace silkworm::sentry::common { +namespace silkworm::sentry { class EnodeUrl { public: explicit EnodeUrl(const std::string& url_str); - EnodeUrl(common::EccPublicKey public_key, boost::asio::ip::address ip, uint16_t port) + EnodeUrl(EccPublicKey public_key, boost::asio::ip::address ip, uint16_t port) : public_key_(std::move(public_key)), ip_(std::move(ip)), port_(port) {} - [[nodiscard]] const common::EccPublicKey& public_key() const { return public_key_; } + [[nodiscard]] const EccPublicKey& public_key() const { return public_key_; } [[nodiscard]] const boost::asio::ip::address& ip() const { return ip_; } [[nodiscard]] uint16_t port() const { return port_; } @@ -43,9 +43,9 @@ class EnodeUrl { friend bool operator==(const EnodeUrl&, const EnodeUrl&) = default; private: - common::EccPublicKey public_key_; + EccPublicKey public_key_; boost::asio::ip::address ip_; uint16_t port_; }; -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/enode_url_test.cpp b/silkworm/sentry/common/enode_url_test.cpp index 3e1081bca2..b671f79ecc 100644 --- a/silkworm/sentry/common/enode_url_test.cpp +++ b/silkworm/sentry/common/enode_url_test.cpp @@ -18,7 +18,7 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { TEST_CASE("EnodeUrl") { EnodeUrl url1("enode://24bfa2cdce7c6a41184fa0809ad8d76969b7280952e9aa46179d90cfbab90f7d2b004928f0364389a1aa8d5166281f2ff7568493c1f719e8f6148ef8cf8af42d@1.2.3.4:5"); @@ -37,4 +37,4 @@ TEST_CASE("EnodeUrl") { CHECK_THROWS(EnodeUrl("enode://24bfa2cdce7c6a41184fa0809ad8d76969b7280952e9aa46179d90cfbab90f7d2b004928f0364389a1aa8d5166281f2ff7568493c1f719e8f6148ef8cf8af42d@1.2.3.4")); } -} // namespace silkworm::sentry::common \ No newline at end of file +} // namespace silkworm::sentry \ No newline at end of file diff --git a/silkworm/sentry/common/message.hpp b/silkworm/sentry/common/message.hpp index 8681c7224e..fb701d58de 100644 --- a/silkworm/sentry/common/message.hpp +++ b/silkworm/sentry/common/message.hpp @@ -18,11 +18,11 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { struct Message { uint8_t id{0}; Bytes data; }; -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/random.cpp b/silkworm/sentry/common/random.cpp index 9dd06ac06b..f0e5f586b2 100644 --- a/silkworm/sentry/common/random.cpp +++ b/silkworm/sentry/common/random.cpp @@ -16,7 +16,7 @@ #include "random.hpp" -namespace silkworm::sentry::common { +namespace silkworm::sentry { Bytes random_bytes(Bytes::size_type size) { std::default_random_engine random_engine{std::random_device{}()}; @@ -29,4 +29,4 @@ Bytes random_bytes(Bytes::size_type size) { return data; } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/random.hpp b/silkworm/sentry/common/random.hpp index 688cef95e3..8ab91eb29e 100644 --- a/silkworm/sentry/common/random.hpp +++ b/silkworm/sentry/common/random.hpp @@ -25,7 +25,7 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { Bytes random_bytes(Bytes::size_type size); @@ -74,4 +74,4 @@ std::vector random_vector_items(std::vector& l, size_t max_count) { return out; } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/sleep.cpp b/silkworm/sentry/common/sleep.cpp index fdf94d8478..3d3da36c19 100644 --- a/silkworm/sentry/common/sleep.cpp +++ b/silkworm/sentry/common/sleep.cpp @@ -21,7 +21,7 @@ #include #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { using namespace boost::asio; @@ -32,4 +32,4 @@ Task sleep(std::chrono::milliseconds duration) { co_await timer.async_wait(use_awaitable); } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/sleep.hpp b/silkworm/sentry/common/sleep.hpp index 197a7c5c6e..57c98ad68c 100644 --- a/silkworm/sentry/common/sleep.hpp +++ b/silkworm/sentry/common/sleep.hpp @@ -20,8 +20,8 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { Task sleep(std::chrono::milliseconds duration); -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/socket_stream.cpp b/silkworm/sentry/common/socket_stream.cpp index 5682ddc5a0..a8d6d732ae 100644 --- a/silkworm/sentry/common/socket_stream.cpp +++ b/silkworm/sentry/common/socket_stream.cpp @@ -23,7 +23,7 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { using namespace boost::asio; @@ -55,4 +55,4 @@ Task SocketStream::receive_size_and_data(Bytes& raw_data) { co_return ByteView(data_ptr, size); } -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/common/socket_stream.hpp b/silkworm/sentry/common/socket_stream.hpp index 3141a0d3b6..96240d4cf7 100644 --- a/silkworm/sentry/common/socket_stream.hpp +++ b/silkworm/sentry/common/socket_stream.hpp @@ -24,7 +24,7 @@ #include -namespace silkworm::sentry::common { +namespace silkworm::sentry { class SocketStream { public: @@ -48,4 +48,4 @@ class SocketStream { boost::asio::ip::tcp::socket socket_; }; -} // namespace silkworm::sentry::common +} // namespace silkworm::sentry diff --git a/silkworm/sentry/discovery/disc_v4/disc_v4_common/message_expiration.cpp b/silkworm/sentry/discovery/disc_v4/common/message_expiration.cpp similarity index 88% rename from silkworm/sentry/discovery/disc_v4/disc_v4_common/message_expiration.cpp rename to silkworm/sentry/discovery/disc_v4/common/message_expiration.cpp index 220b8d6ba3..dbed224b1d 100644 --- a/silkworm/sentry/discovery/disc_v4/disc_v4_common/message_expiration.cpp +++ b/silkworm/sentry/discovery/disc_v4/common/message_expiration.cpp @@ -16,7 +16,7 @@ #include "message_expiration.hpp" -namespace silkworm::sentry::discovery::disc_v4::disc_v4_common { +namespace silkworm::sentry::discovery::disc_v4 { std::chrono::time_point make_message_expiration() { using namespace std::chrono_literals; @@ -28,4 +28,4 @@ bool is_expired_message_expiration(std::chrono::time_point -namespace silkworm::sentry::discovery::disc_v4::disc_v4_common { +namespace silkworm::sentry::discovery::disc_v4 { std::chrono::time_point make_message_expiration(); bool is_expired_message_expiration(std::chrono::time_point expiration); -} // namespace silkworm::sentry::discovery::disc_v4::disc_v4_common +} // namespace silkworm::sentry::discovery::disc_v4 diff --git a/silkworm/sentry/discovery/disc_v4/disc_v4_common/node_address.cpp b/silkworm/sentry/discovery/disc_v4/common/node_address.cpp similarity index 95% rename from silkworm/sentry/discovery/disc_v4/disc_v4_common/node_address.cpp rename to silkworm/sentry/discovery/disc_v4/common/node_address.cpp index 2408a0638a..88612a8d4e 100644 --- a/silkworm/sentry/discovery/disc_v4/disc_v4_common/node_address.cpp +++ b/silkworm/sentry/discovery/disc_v4/common/node_address.cpp @@ -21,7 +21,7 @@ #include #include -namespace silkworm::sentry::discovery::disc_v4::disc_v4_common { +namespace silkworm::sentry::discovery::disc_v4 { Bytes ip_address_to_bytes(const boost::asio::ip::address& ip) { if (ip.is_v4()) { @@ -77,4 +77,4 @@ DecodingResult decode(ByteView& from, NodeAddress& to, rlp::Leftover mode) noexc return result; } -} // namespace silkworm::sentry::discovery::disc_v4::disc_v4_common +} // namespace silkworm::sentry::discovery::disc_v4 diff --git a/silkworm/sentry/discovery/disc_v4/disc_v4_common/node_address.hpp b/silkworm/sentry/discovery/disc_v4/common/node_address.hpp similarity index 90% rename from silkworm/sentry/discovery/disc_v4/disc_v4_common/node_address.hpp rename to silkworm/sentry/discovery/disc_v4/common/node_address.hpp index 26d2b4ca4a..a5d3b50518 100644 --- a/silkworm/sentry/discovery/disc_v4/disc_v4_common/node_address.hpp +++ b/silkworm/sentry/discovery/disc_v4/common/node_address.hpp @@ -26,7 +26,7 @@ #include #include -namespace silkworm::sentry::discovery::disc_v4::disc_v4_common { +namespace silkworm::sentry::discovery::disc_v4 { struct NodeAddress { boost::asio::ip::udp::endpoint endpoint; @@ -42,4 +42,4 @@ DecodingResult decode(ByteView& from, NodeAddress& to, rlp::Leftover mode) noexc Bytes ip_address_to_bytes(const boost::asio::ip::address& ip); std::optional ip_address_from_bytes(ByteView ip_bytes) noexcept; -} // namespace silkworm::sentry::discovery::disc_v4::disc_v4_common +} // namespace silkworm::sentry::discovery::disc_v4 diff --git a/silkworm/sentry/discovery/disc_v4/disc_v4_common/packet_type.hpp b/silkworm/sentry/discovery/disc_v4/common/packet_type.hpp similarity index 85% rename from silkworm/sentry/discovery/disc_v4/disc_v4_common/packet_type.hpp rename to silkworm/sentry/discovery/disc_v4/common/packet_type.hpp index 5cd5e9d860..05a1779751 100644 --- a/silkworm/sentry/discovery/disc_v4/disc_v4_common/packet_type.hpp +++ b/silkworm/sentry/discovery/disc_v4/common/packet_type.hpp @@ -18,7 +18,7 @@ #include -namespace silkworm::sentry::discovery::disc_v4::disc_v4_common { +namespace silkworm::sentry::discovery::disc_v4 { enum class PacketType : uint8_t { kPing = 1, @@ -30,4 +30,4 @@ enum class PacketType : uint8_t { kMaxValue = kEnrResponse, }; -} // namespace silkworm::sentry::discovery::disc_v4::disc_v4_common +} // namespace silkworm::sentry::discovery::disc_v4 diff --git a/silkworm/sentry/discovery/disc_v4/discovery.cpp b/silkworm/sentry/discovery/disc_v4/discovery.cpp index bf8130e72f..d39d10415e 100644 --- a/silkworm/sentry/discovery/disc_v4/discovery.cpp +++ b/silkworm/sentry/discovery/disc_v4/discovery.cpp @@ -28,7 +28,7 @@ class DiscoveryImpl : private MessageHandler { public: DiscoveryImpl( uint16_t server_port, - std::function node_key, + std::function node_key, node_db::NodeDb& node_db) : server_(server_port, std::move(node_key), *this), node_db_(node_db) {} @@ -65,7 +65,7 @@ class DiscoveryImpl : private MessageHandler { Discovery::Discovery( uint16_t server_port, - std::function node_key, + std::function node_key, node_db::NodeDb& node_db) : p_impl_(std::make_unique(server_port, std::move(node_key), node_db)) {} diff --git a/silkworm/sentry/discovery/disc_v4/discovery.hpp b/silkworm/sentry/discovery/disc_v4/discovery.hpp index 57aa3fe502..c9d8c739d2 100644 --- a/silkworm/sentry/discovery/disc_v4/discovery.hpp +++ b/silkworm/sentry/discovery/disc_v4/discovery.hpp @@ -32,7 +32,7 @@ class Discovery { public: Discovery( uint16_t server_port, - std::function node_key, + std::function node_key, node_db::NodeDb& node_db); ~Discovery(); diff --git a/silkworm/sentry/discovery/disc_v4/find/find_node_message.cpp b/silkworm/sentry/discovery/disc_v4/find/find_node_message.cpp index 45d9680f93..cc4ce2d87b 100644 --- a/silkworm/sentry/discovery/disc_v4/find/find_node_message.cpp +++ b/silkworm/sentry/discovery/disc_v4/find/find_node_message.cpp @@ -20,12 +20,10 @@ #include #include #include -#include +#include namespace silkworm::sentry::discovery::disc_v4::find { -using namespace disc_v4_common; - const uint8_t FindNodeMessage::kId = static_cast(PacketType::kFindNode); Bytes FindNodeMessage::rlp_encode() const { @@ -49,7 +47,7 @@ FindNodeMessage FindNodeMessage::rlp_decode(ByteView data) { } return FindNodeMessage{ - common::EccPublicKey::deserialize(target_public_key_data), + EccPublicKey::deserialize(target_public_key_data), time_point_from_unix_timestamp(expiration_ts), }; } diff --git a/silkworm/sentry/discovery/disc_v4/find/find_node_message.hpp b/silkworm/sentry/discovery/disc_v4/find/find_node_message.hpp index 54eea86abc..6a100dc6b1 100644 --- a/silkworm/sentry/discovery/disc_v4/find/find_node_message.hpp +++ b/silkworm/sentry/discovery/disc_v4/find/find_node_message.hpp @@ -24,7 +24,7 @@ namespace silkworm::sentry::discovery::disc_v4::find { struct FindNodeMessage { - common::EccPublicKey target_public_key; + EccPublicKey target_public_key; std::chrono::time_point expiration; [[nodiscard]] Bytes rlp_encode() const; diff --git a/silkworm/sentry/discovery/disc_v4/find/neighbors_message.cpp b/silkworm/sentry/discovery/disc_v4/find/neighbors_message.cpp index 9627bbe7de..e326a69992 100644 --- a/silkworm/sentry/discovery/disc_v4/find/neighbors_message.cpp +++ b/silkworm/sentry/discovery/disc_v4/find/neighbors_message.cpp @@ -23,17 +23,15 @@ #include #include #include -#include +#include namespace silkworm::sentry::discovery::disc_v4::find { -using namespace disc_v4_common; - const uint8_t NeighborsMessage::kId = static_cast(PacketType::kNeighbors); struct NeighborsNodeInfo { NodeAddress address; - common::EccPublicKey public_key{Bytes{}}; + EccPublicKey public_key{Bytes{}}; }; //! RLP length of NeighborsNodeInfo @@ -66,7 +64,7 @@ DecodingResult decode(ByteView& from, NeighborsNodeInfo& to, rlp::Leftover mode) to.address.endpoint = boost::asio::ip::udp::endpoint(*ip, port); try { - to.public_key = common::EccPublicKey::deserialize(public_key_data); + to.public_key = EccPublicKey::deserialize(public_key_data); } catch (const std::runtime_error&) { return tl::unexpected{DecodingError::kUnexpectedString}; } @@ -101,7 +99,7 @@ NeighborsMessage NeighborsMessage::rlp_decode(ByteView data) { throw DecodingException(result.error(), "Failed to decode NeighborsMessage RLP"); } - std::map node_addresses; + std::map node_addresses; for (auto& info : node_infos) { node_addresses[info.public_key] = info.address; } diff --git a/silkworm/sentry/discovery/disc_v4/find/neighbors_message.hpp b/silkworm/sentry/discovery/disc_v4/find/neighbors_message.hpp index 5ea0243ade..844016f626 100644 --- a/silkworm/sentry/discovery/disc_v4/find/neighbors_message.hpp +++ b/silkworm/sentry/discovery/disc_v4/find/neighbors_message.hpp @@ -21,12 +21,12 @@ #include #include -#include +#include namespace silkworm::sentry::discovery::disc_v4::find { struct NeighborsMessage { - std::map node_addresses; + std::map node_addresses; std::chrono::time_point expiration; [[nodiscard]] Bytes rlp_encode() const; diff --git a/silkworm/sentry/discovery/disc_v4/message_codec.cpp b/silkworm/sentry/discovery/disc_v4/message_codec.cpp index 6d13b0cc04..7337bc9b5a 100644 --- a/silkworm/sentry/discovery/disc_v4/message_codec.cpp +++ b/silkworm/sentry/discovery/disc_v4/message_codec.cpp @@ -24,7 +24,7 @@ #include #include -#include "disc_v4_common/packet_type.hpp" +#include "common/packet_type.hpp" namespace silkworm::sentry::discovery::disc_v4 { @@ -38,9 +38,9 @@ struct Packet { }; #pragma pack(pop) -using namespace common::crypto; +using namespace crypto; -Bytes MessageCodec::encode(const common::Message& message, ByteView private_key) { +Bytes MessageCodec::encode(const Message& message, ByteView private_key) { Bytes packet_data(sizeof(Packet) + message.data.size() - 1, 0); auto packet = reinterpret_cast(packet_data.data()); @@ -69,7 +69,7 @@ MessageEnvelope MessageCodec::decode(ByteView packet_data) { throw std::runtime_error("MessageCodec: packet is too big"); auto packet = reinterpret_cast(packet_data.data()); - if ((packet->type == 0) || (packet->type > static_cast(disc_v4_common::PacketType::kMaxValue))) + if ((packet->type == 0) || (packet->type > static_cast(PacketType::kMaxValue))) throw std::runtime_error("MessageCodec: invalid type"); auto expected_hash = keccak256(packet_data.substr(offsetof(Packet, signature))); @@ -81,7 +81,7 @@ MessageEnvelope MessageCodec::decode(ByteView packet_data) { ByteView(type_and_data_hash.bytes), ByteView(packet->signature)); - common::Message message{ + Message message{ packet->type, Bytes(packet_data.substr(offsetof(Packet, data))), }; diff --git a/silkworm/sentry/discovery/disc_v4/message_codec.hpp b/silkworm/sentry/discovery/disc_v4/message_codec.hpp index f9c6b52ad9..d42b0609da 100644 --- a/silkworm/sentry/discovery/disc_v4/message_codec.hpp +++ b/silkworm/sentry/discovery/disc_v4/message_codec.hpp @@ -23,13 +23,13 @@ namespace silkworm::sentry::discovery::disc_v4 { struct MessageEnvelope { - common::Message message; - common::EccPublicKey public_key; + Message message; + EccPublicKey public_key; Bytes packet_hash; }; struct MessageCodec { - static Bytes encode(const common::Message& message, ByteView private_key); + static Bytes encode(const Message& message, ByteView private_key); static ByteView encoded_packet_hash(ByteView packet_data); static MessageEnvelope decode(ByteView packet_data); }; diff --git a/silkworm/sentry/discovery/disc_v4/message_codec_test.cpp b/silkworm/sentry/discovery/disc_v4/message_codec_test.cpp index 31f4cde052..2bad895316 100644 --- a/silkworm/sentry/discovery/disc_v4/message_codec_test.cpp +++ b/silkworm/sentry/discovery/disc_v4/message_codec_test.cpp @@ -26,23 +26,22 @@ #include #include -#include "disc_v4_common/packet_type.hpp" +#include "common/packet_type.hpp" #include "find/find_node_message.hpp" #include "find/neighbors_message.hpp" #include "ping/ping_message.hpp" namespace silkworm::sentry::discovery::disc_v4 { -using namespace disc_v4_common; using namespace boost::asio::ip; -static common::EccKeyPair test_key_pair() { +static EccKeyPair test_key_pair() { constexpr std::string_view kPrivateKey = "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"; - return common::EccKeyPair{from_hex(kPrivateKey).value()}; + return EccKeyPair{from_hex(kPrivateKey).value()}; } TEST_CASE("MessageCodec.ping_encode_and_decode") { - common::EccKeyPair key_pair = test_key_pair(); + EccKeyPair key_pair = test_key_pair(); ping::PingMessage expected_ping_message{ udp::endpoint{make_address("10.0.0.1"), 100}, 101, @@ -50,7 +49,7 @@ TEST_CASE("MessageCodec.ping_encode_and_decode") { std::chrono::system_clock::now(), }; - common::Message expected_message{static_cast(PacketType::kPing), expected_ping_message.rlp_encode()}; + Message expected_message{static_cast(PacketType::kPing), expected_ping_message.rlp_encode()}; Bytes expected_message_data = MessageCodec::encode(expected_message, key_pair.private_key()); auto [decoded_message, decoded_public_key, decoded_packet_hash] = MessageCodec::decode(expected_message_data); @@ -135,7 +134,7 @@ TEST_CASE("MessageCodec.neighbors_decode") { }; for (const auto& [expected_public_key_hex, expected_address] : expected_nodes) { - auto expected_public_key = common::EccPublicKey::deserialize_hex(expected_public_key_hex); + auto expected_public_key = EccPublicKey::deserialize_hex(expected_public_key_hex); REQUIRE(neighbors_message.node_addresses.count(expected_public_key)); auto& address = neighbors_message.node_addresses[expected_public_key]; CHECK(address.endpoint == expected_address.endpoint); diff --git a/silkworm/sentry/discovery/disc_v4/ping/ping_handler.cpp b/silkworm/sentry/discovery/disc_v4/ping/ping_handler.cpp index 8548b3be47..6df6fa662e 100644 --- a/silkworm/sentry/discovery/disc_v4/ping/ping_handler.cpp +++ b/silkworm/sentry/discovery/disc_v4/ping/ping_handler.cpp @@ -16,14 +16,12 @@ #include "ping_handler.hpp" -#include +#include #include "pong_message.hpp" namespace silkworm::sentry::discovery::disc_v4::ping { -using namespace disc_v4_common; - Task PingHandler::handle( PingMessage message, boost::asio::ip::udp::endpoint sender_endpoint, diff --git a/silkworm/sentry/discovery/disc_v4/ping/ping_message.cpp b/silkworm/sentry/discovery/disc_v4/ping/ping_message.cpp index ee24daed67..55d79873d5 100644 --- a/silkworm/sentry/discovery/disc_v4/ping/ping_message.cpp +++ b/silkworm/sentry/discovery/disc_v4/ping/ping_message.cpp @@ -20,13 +20,11 @@ #include #include #include -#include -#include +#include +#include namespace silkworm::sentry::discovery::disc_v4::ping { -using namespace disc_v4_common; - const uint8_t PingMessage::kId = static_cast(PacketType::kPing); Bytes PingMessage::rlp_encode() const { diff --git a/silkworm/sentry/discovery/disc_v4/ping/pong_message.cpp b/silkworm/sentry/discovery/disc_v4/ping/pong_message.cpp index c204df3362..c09b52a082 100644 --- a/silkworm/sentry/discovery/disc_v4/ping/pong_message.cpp +++ b/silkworm/sentry/discovery/disc_v4/ping/pong_message.cpp @@ -20,13 +20,11 @@ #include #include #include -#include -#include +#include +#include namespace silkworm::sentry::discovery::disc_v4::ping { -using namespace disc_v4_common; - const uint8_t PongMessage::kId = static_cast(PacketType::kPong); Bytes PongMessage::rlp_encode() const { diff --git a/silkworm/sentry/discovery/disc_v4/server.cpp b/silkworm/sentry/discovery/disc_v4/server.cpp index cb10300503..cb2b1c2efd 100644 --- a/silkworm/sentry/discovery/disc_v4/server.cpp +++ b/silkworm/sentry/discovery/disc_v4/server.cpp @@ -31,17 +31,16 @@ #include #include -#include "disc_v4_common/packet_type.hpp" +#include "common/packet_type.hpp" #include "message_codec.hpp" namespace silkworm::sentry::discovery::disc_v4 { using namespace boost::asio; -using namespace disc_v4_common; class ServerImpl { public: - explicit ServerImpl(uint16_t port, std::function node_key, MessageHandler& handler) + explicit ServerImpl(uint16_t port, std::function node_key, MessageHandler& handler) : ip_(ip::address{ip::address_v4::any()}), port_(port), node_key_(std::move(node_key)), @@ -121,7 +120,7 @@ class ServerImpl { template Task send_message(TMessage message, ip::udp::endpoint recipient) { auto packet_data = MessageCodec::encode( - common::Message{TMessage::kId, message.rlp_encode()}, + Message{TMessage::kId, message.rlp_encode()}, node_key_().private_key()); co_await send_packet(std::move(packet_data), recipient); } @@ -143,11 +142,11 @@ class ServerImpl { boost::asio::ip::address ip_; uint16_t port_; - std::function node_key_; + std::function node_key_; MessageHandler& handler_; }; -Server::Server(uint16_t port, std::function node_key, MessageHandler& handler) +Server::Server(uint16_t port, std::function node_key, MessageHandler& handler) : p_impl_(std::make_unique(port, std::move(node_key), handler)) {} Server::~Server() { diff --git a/silkworm/sentry/discovery/disc_v4/server.hpp b/silkworm/sentry/discovery/disc_v4/server.hpp index af07735bf6..4f919bbed5 100644 --- a/silkworm/sentry/discovery/disc_v4/server.hpp +++ b/silkworm/sentry/discovery/disc_v4/server.hpp @@ -32,7 +32,7 @@ class ServerImpl; class Server : public MessageSender { public: - Server(uint16_t port, std::function node_key, MessageHandler& handler); + Server(uint16_t port, std::function node_key, MessageHandler& handler); ~Server() override; Server(const Server&) = delete; diff --git a/silkworm/sentry/discovery/discovery.cpp b/silkworm/sentry/discovery/discovery.cpp index cd897452a6..4e6a39a033 100644 --- a/silkworm/sentry/discovery/discovery.cpp +++ b/silkworm/sentry/discovery/discovery.cpp @@ -33,10 +33,10 @@ using namespace boost::asio; class DiscoveryImpl { public: explicit DiscoveryImpl( - std::vector peer_urls, + std::vector peer_urls, bool with_dynamic_discovery, const std::filesystem::path& data_dir_path, - std::function node_key, + std::function node_key, uint16_t disc_v4_port); DiscoveryImpl(const DiscoveryImpl&) = delete; @@ -44,16 +44,16 @@ class DiscoveryImpl { Task run(); - Task> request_peer_urls( + Task> request_peer_urls( size_t max_count, - std::vector exclude_urls); + std::vector exclude_urls); - bool is_static_peer_url(const common::EnodeUrl& peer_url); + bool is_static_peer_url(const EnodeUrl& peer_url); private: void setup_node_db(); - const std::vector peer_urls_; + const std::vector peer_urls_; bool with_dynamic_discovery_; std::filesystem::path data_dir_path_; node_db::NodeDbSqlite node_db_; @@ -61,10 +61,10 @@ class DiscoveryImpl { }; DiscoveryImpl::DiscoveryImpl( - std::vector peer_urls, + std::vector peer_urls, bool with_dynamic_discovery, const std::filesystem::path& data_dir_path, - std::function node_key, + std::function node_key, uint16_t disc_v4_port) : peer_urls_(std::move(peer_urls)), with_dynamic_discovery_(with_dynamic_discovery), @@ -99,24 +99,24 @@ static std::vector exclude_vector_items( return remaining_items; } -Task> DiscoveryImpl::request_peer_urls( +Task> DiscoveryImpl::request_peer_urls( size_t max_count, - std::vector exclude_urls) { + std::vector exclude_urls) { auto peer_urls = exclude_vector_items(peer_urls_, std::move(exclude_urls)); - co_return common::random_vector_items(peer_urls, max_count); + co_return random_vector_items(peer_urls, max_count); } -bool DiscoveryImpl::is_static_peer_url(const common::EnodeUrl& peer_url) { - return std::any_of(peer_urls_.cbegin(), peer_urls_.cend(), [&peer_url](const common::EnodeUrl& it) { +bool DiscoveryImpl::is_static_peer_url(const EnodeUrl& peer_url) { + return std::any_of(peer_urls_.cbegin(), peer_urls_.cend(), [&peer_url](const EnodeUrl& it) { return it == peer_url; }); } Discovery::Discovery( - std::vector peer_urls, + std::vector peer_urls, bool with_dynamic_discovery, const std::filesystem::path& data_dir_path, - std::function node_key, + std::function node_key, uint16_t disc_v4_port) : p_impl_(std::make_unique( std::move(peer_urls), @@ -133,13 +133,13 @@ Task Discovery::run() { return p_impl_->run(); } -Task> Discovery::request_peer_urls( +Task> Discovery::request_peer_urls( size_t max_count, - std::vector exclude_urls) { + std::vector exclude_urls) { return p_impl_->request_peer_urls(max_count, std::move(exclude_urls)); } -bool Discovery::is_static_peer_url(const common::EnodeUrl& peer_url) { +bool Discovery::is_static_peer_url(const EnodeUrl& peer_url) { return p_impl_->is_static_peer_url(peer_url); } diff --git a/silkworm/sentry/discovery/discovery.hpp b/silkworm/sentry/discovery/discovery.hpp index a6811b7b90..2f521a62d9 100644 --- a/silkworm/sentry/discovery/discovery.hpp +++ b/silkworm/sentry/discovery/discovery.hpp @@ -33,10 +33,10 @@ class DiscoveryImpl; class Discovery { public: explicit Discovery( - std::vector peer_urls, + std::vector peer_urls, bool with_dynamic_discovery, const std::filesystem::path& data_dir_path, - std::function node_key, + std::function node_key, uint16_t disc_v4_port); ~Discovery(); @@ -45,11 +45,11 @@ class Discovery { Task run(); - Task> request_peer_urls( + Task> request_peer_urls( size_t max_count, - std::vector exclude_urls); + std::vector exclude_urls); - bool is_static_peer_url(const common::EnodeUrl& peer_url); + bool is_static_peer_url(const EnodeUrl& peer_url); private: std::unique_ptr p_impl_; diff --git a/silkworm/sentry/discovery/node_db/node_db.hpp b/silkworm/sentry/discovery/node_db/node_db.hpp index e1809232de..f0b9d17461 100644 --- a/silkworm/sentry/discovery/node_db/node_db.hpp +++ b/silkworm/sentry/discovery/node_db/node_db.hpp @@ -27,7 +27,7 @@ namespace silkworm::sentry::discovery::node_db { -using NodeId = common::EccPublicKey; +using NodeId = EccPublicKey; using Time = std::chrono::time_point; struct NodeAddress { diff --git a/silkworm/sentry/eth/protocol.cpp b/silkworm/sentry/eth/protocol.cpp index b76a80de5a..a07d92fcf1 100644 --- a/silkworm/sentry/eth/protocol.cpp +++ b/silkworm/sentry/eth/protocol.cpp @@ -22,7 +22,7 @@ namespace silkworm::sentry::eth { const uint8_t Protocol::kVersion = 68; -void Protocol::handle_peer_first_message(const common::Message& message) { +void Protocol::handle_peer_first_message(const Message& message) { if (message.id != StatusMessage::kId) throw std::runtime_error("eth::Protocol: unexpected first message id=" + std::to_string(message.id)); diff --git a/silkworm/sentry/eth/protocol.hpp b/silkworm/sentry/eth/protocol.hpp index 2b47381ff1..b1bb5af1c5 100644 --- a/silkworm/sentry/eth/protocol.hpp +++ b/silkworm/sentry/eth/protocol.hpp @@ -37,12 +37,12 @@ class Protocol : public rlpx::Protocol { return {"eth", Protocol::kVersion}; } - [[nodiscard]] common::Message first_message() override { + [[nodiscard]] Message first_message() override { auto status = status_provider_(); return status.message.to_message(); } - void handle_peer_first_message(const common::Message& message) override; + void handle_peer_first_message(const Message& message) override; static const uint8_t kVersion; diff --git a/silkworm/sentry/eth/status_message.cpp b/silkworm/sentry/eth/status_message.cpp index 4f21122beb..794fce5136 100644 --- a/silkworm/sentry/eth/status_message.cpp +++ b/silkworm/sentry/eth/status_message.cpp @@ -24,8 +24,6 @@ namespace silkworm::sentry::eth { -using common::Message; - const uint8_t StatusMessage::kId = 16; Bytes StatusMessage::rlp_encode() const { diff --git a/silkworm/sentry/eth/status_message.hpp b/silkworm/sentry/eth/status_message.hpp index 4b7471fe47..4acad0b840 100644 --- a/silkworm/sentry/eth/status_message.hpp +++ b/silkworm/sentry/eth/status_message.hpp @@ -29,8 +29,8 @@ struct StatusMessage { [[nodiscard]] Bytes rlp_encode() const; [[nodiscard]] static StatusMessage rlp_decode(ByteView data); - [[nodiscard]] common::Message to_message() const; - [[nodiscard]] static StatusMessage from_message(const common::Message& message); + [[nodiscard]] Message to_message() const; + [[nodiscard]] static StatusMessage from_message(const Message& message); uint8_t version; uint64_t network_id; diff --git a/silkworm/sentry/grpc/client/sentry_client.cpp b/silkworm/sentry/grpc/client/sentry_client.cpp index bc6591c1fb..5badd9fb46 100644 --- a/silkworm/sentry/grpc/client/sentry_client.cpp +++ b/silkworm/sentry/grpc/client/sentry_client.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include "../interfaces/eth_version.hpp" #include "../interfaces/message.hpp" @@ -44,13 +44,13 @@ namespace silkworm::sentry::grpc::client { namespace proto = ::sentry; using Stub = proto::Sentry::Stub; namespace sw_rpc = silkworm::rpc; -using namespace api::api_common; +using namespace api; static std::shared_ptr<::grpc::Channel> make_grpc_channel(const std::string& address_uri) { return ::grpc::CreateChannel(address_uri, ::grpc::InsecureChannelCredentials()); } -class SentryClientImpl final : public api::api_common::Service { +class SentryClientImpl final : public api::Service { public: explicit SentryClientImpl(const std::string& address_uri, agrpc::GrpcContext& grpc_context) : channel_(make_grpc_channel(address_uri)), @@ -99,7 +99,7 @@ class SentryClientImpl final : public api::api_common::Service { } // rpc SendMessageById(SendMessageByIdRequest) returns (SentPeers); - Task send_message_by_id(common::Message message, common::EccPublicKey public_key) override { + Task send_message_by_id(Message message, EccPublicKey public_key) override { proto::SendMessageByIdRequest request; request.mutable_data()->CopyFrom(interfaces::outbound_data_from_message(message)); request.mutable_peer_id()->CopyFrom(interfaces::peer_id_from_public_key(public_key)); @@ -110,7 +110,7 @@ class SentryClientImpl final : public api::api_common::Service { } // rpc SendMessageToRandomPeers(SendMessageToRandomPeersRequest) returns (SentPeers); - Task send_message_to_random_peers(common::Message message, size_t max_peers) override { + Task send_message_to_random_peers(Message message, size_t max_peers) override { proto::SendMessageToRandomPeersRequest request; request.mutable_data()->CopyFrom(interfaces::outbound_data_from_message(message)); request.set_max_peers(max_peers); @@ -121,7 +121,7 @@ class SentryClientImpl final : public api::api_common::Service { } // rpc SendMessageToAll(OutboundMessageData) returns (SentPeers); - Task send_message_to_all(common::Message message) override { + Task send_message_to_all(Message message) override { proto::OutboundMessageData request = interfaces::outbound_data_from_message(message); proto::SentPeers reply = co_await sw_rpc::unary_rpc_with_retries(&Stub::AsyncSendMessageToAll, stub_, std::move(request), grpc_context_, on_disconnect_, *channel_); auto result = interfaces::peer_keys_from_sent_peers_ids(reply); @@ -129,7 +129,7 @@ class SentryClientImpl final : public api::api_common::Service { } // rpc SendMessageByMinBlock(SendMessageByMinBlockRequest) returns (SentPeers); - Task send_message_by_min_block(common::Message message, size_t max_peers) override { + Task send_message_by_min_block(Message message, size_t max_peers) override { proto::SendMessageByMinBlockRequest request; request.mutable_data()->CopyFrom(interfaces::outbound_data_from_message(message)); // TODO: set_min_block @@ -142,7 +142,7 @@ class SentryClientImpl final : public api::api_common::Service { } // rpc PeerMinBlock(PeerMinBlockRequest) returns (google.protobuf.Empty); - Task peer_min_block(common::EccPublicKey public_key) override { + Task peer_min_block(EccPublicKey public_key) override { proto::PeerMinBlockRequest request; request.mutable_peer_id()->CopyFrom(interfaces::peer_id_from_public_key(public_key)); // TODO: set_min_block @@ -192,7 +192,7 @@ class SentryClientImpl final : public api::api_common::Service { } // rpc PeerById(PeerByIdRequest) returns (PeerByIdReply); - Task> peer_by_id(common::EccPublicKey public_key) override { + Task> peer_by_id(EccPublicKey public_key) override { proto::PeerByIdRequest request; request.mutable_peer_id()->CopyFrom(interfaces::peer_id_from_public_key(public_key)); proto::PeerByIdReply reply = co_await sw_rpc::unary_rpc_with_retries(&Stub::AsyncPeerById, stub_, std::move(request), grpc_context_, on_disconnect_, *channel_); @@ -201,7 +201,7 @@ class SentryClientImpl final : public api::api_common::Service { } // rpc PenalizePeer(PenalizePeerRequest) returns (google.protobuf.Empty); - Task penalize_peer(common::EccPublicKey public_key) override { + Task penalize_peer(EccPublicKey public_key) override { proto::PenalizePeerRequest request; request.mutable_peer_id()->CopyFrom(interfaces::peer_id_from_public_key(public_key)); request.set_penalty(proto::PenaltyKind::Kick); @@ -242,7 +242,7 @@ SentryClient::~SentryClient() { log::Trace("sentry") << "silkworm::sentry::grpc::client::SentryClient::~SentryClient"; } -Task> SentryClient::service() { +Task> SentryClient::service() { co_return p_impl_; } diff --git a/silkworm/sentry/grpc/client/sentry_client.hpp b/silkworm/sentry/grpc/client/sentry_client.hpp index 79b21bd48c..2c2ab12477 100644 --- a/silkworm/sentry/grpc/client/sentry_client.hpp +++ b/silkworm/sentry/grpc/client/sentry_client.hpp @@ -21,13 +21,13 @@ #include -#include +#include namespace silkworm::sentry::grpc::client { class SentryClientImpl; -class SentryClient : public api::api_common::SentryClient { +class SentryClient : public api::SentryClient { public: explicit SentryClient(const std::string& address_uri, agrpc::GrpcContext& grpc_context); ~SentryClient() override; @@ -35,7 +35,7 @@ class SentryClient : public api::api_common::SentryClient { SentryClient(SentryClient&&) = default; SentryClient& operator=(SentryClient&&) = default; - Task> service() override; + Task> service() override; [[nodiscard]] bool is_ready() override; void on_disconnect(std::function()> callback) override; diff --git a/silkworm/sentry/grpc/interfaces/message.cpp b/silkworm/sentry/grpc/interfaces/message.cpp index d10492ffd0..f1f54a79d0 100644 --- a/silkworm/sentry/grpc/interfaces/message.cpp +++ b/silkworm/sentry/grpc/interfaces/message.cpp @@ -119,36 +119,36 @@ static Bytes bytes_from_string(const std::string& s) { return Bytes{reinterpret_cast(s.data()), s.size()}; } -sentry::common::Message message_from_outbound_data(const proto::OutboundMessageData& message_data) { +sentry::Message message_from_outbound_data(const proto::OutboundMessageData& message_data) { return { message_id_from_proto_message_id(message_data.id()), bytes_from_string(message_data.data()), }; } -proto::OutboundMessageData outbound_data_from_message(const sentry::common::Message& message) { +proto::OutboundMessageData outbound_data_from_message(const sentry::Message& message) { proto::OutboundMessageData result; result.set_id(proto_message_id_from_message_id(message.id)); result.set_data(message.data.data(), message.data.size()); return result; } -sentry::common::Message message_from_inbound_message(const ::sentry::InboundMessage& message_data) { +sentry::Message message_from_inbound_message(const ::sentry::InboundMessage& message_data) { return { message_id_from_proto_message_id(message_data.id()), bytes_from_string(message_data.data()), }; } -proto::InboundMessage inbound_message_from_message(const sentry::common::Message& message) { +proto::InboundMessage inbound_message_from_message(const sentry::Message& message) { proto::InboundMessage result; result.set_id(proto_message_id_from_message_id(message.id)); result.set_data(message.data.data(), message.data.size()); return result; } -api::api_common::MessageIdSet message_id_set_from_messages_request(const proto::MessagesRequest& request) { - api::api_common::MessageIdSet filter; +api::MessageIdSet message_id_set_from_messages_request(const proto::MessagesRequest& request) { + api::MessageIdSet filter; for (int i = 0; i < request.ids_size(); i++) { auto id = request.ids(i); filter.insert(message_id_from_proto_message_id(id)); @@ -156,7 +156,7 @@ api::api_common::MessageIdSet message_id_set_from_messages_request(const proto:: return filter; } -proto::MessagesRequest messages_request_from_message_id_set(const api::api_common::MessageIdSet& message_ids) { +proto::MessagesRequest messages_request_from_message_id_set(const api::MessageIdSet& message_ids) { proto::MessagesRequest result; for (auto id : message_ids) { result.add_ids(proto_message_id_from_message_id(id)); diff --git a/silkworm/sentry/grpc/interfaces/message.hpp b/silkworm/sentry/grpc/interfaces/message.hpp index 0caa948009..33d7432986 100644 --- a/silkworm/sentry/grpc/interfaces/message.hpp +++ b/silkworm/sentry/grpc/interfaces/message.hpp @@ -17,21 +17,21 @@ #pragma once #include -#include +#include #include namespace silkworm::sentry::grpc::interfaces { -sentry::common::Message message_from_outbound_data(const ::sentry::OutboundMessageData& message_data); -::sentry::OutboundMessageData outbound_data_from_message(const sentry::common::Message& message); +sentry::Message message_from_outbound_data(const ::sentry::OutboundMessageData& message_data); +::sentry::OutboundMessageData outbound_data_from_message(const sentry::Message& message); -sentry::common::Message message_from_inbound_message(const ::sentry::InboundMessage& message); -::sentry::InboundMessage inbound_message_from_message(const sentry::common::Message& message); +sentry::Message message_from_inbound_message(const ::sentry::InboundMessage& message); +::sentry::InboundMessage inbound_message_from_message(const sentry::Message& message); uint8_t message_id_from_proto_message_id(::sentry::MessageId message_id); ::sentry::MessageId proto_message_id_from_message_id(uint8_t message_id); -api::api_common::MessageIdSet message_id_set_from_messages_request(const ::sentry::MessagesRequest& request); -::sentry::MessagesRequest messages_request_from_message_id_set(const api::api_common::MessageIdSet& message_ids); +api::MessageIdSet message_id_set_from_messages_request(const ::sentry::MessagesRequest& request); +::sentry::MessagesRequest messages_request_from_message_id_set(const api::MessageIdSet& message_ids); } // namespace silkworm::sentry::grpc::interfaces diff --git a/silkworm/sentry/grpc/interfaces/node_info.cpp b/silkworm/sentry/grpc/interfaces/node_info.cpp index 147963380d..557bea93be 100644 --- a/silkworm/sentry/grpc/interfaces/node_info.cpp +++ b/silkworm/sentry/grpc/interfaces/node_info.cpp @@ -43,16 +43,16 @@ boost::asio::ip::tcp::endpoint parse_endpoint(const std::string& address) { return {ip, port}; } -api::api_common::NodeInfo node_info_from_proto_node_info(const types::NodeInfoReply& info) { - return api::api_common::NodeInfo{ - sentry::common::EnodeUrl{info.enode()}, +api::NodeInfo node_info_from_proto_node_info(const types::NodeInfoReply& info) { + return api::NodeInfo{ + sentry::EnodeUrl{info.enode()}, info.name(), parse_endpoint(info.listener_addr()), static_cast(info.ports().listener()), }; } -types::NodeInfoReply proto_node_info_from_node_info(const api::api_common::NodeInfo& info) { +types::NodeInfoReply proto_node_info_from_node_info(const api::NodeInfo& info) { types::NodeInfoReply reply; reply.set_id(peer_id_string_from_public_key(info.node_url.public_key())); reply.set_name(info.client_id); diff --git a/silkworm/sentry/grpc/interfaces/node_info.hpp b/silkworm/sentry/grpc/interfaces/node_info.hpp index ad9ef0d0ef..d2dac5b9ae 100644 --- a/silkworm/sentry/grpc/interfaces/node_info.hpp +++ b/silkworm/sentry/grpc/interfaces/node_info.hpp @@ -17,11 +17,11 @@ #pragma once #include -#include +#include namespace silkworm::sentry::grpc::interfaces { -api::api_common::NodeInfo node_info_from_proto_node_info(const types::NodeInfoReply& info); -types::NodeInfoReply proto_node_info_from_node_info(const api::api_common::NodeInfo& info); +api::NodeInfo node_info_from_proto_node_info(const types::NodeInfoReply& info); +types::NodeInfoReply proto_node_info_from_node_info(const api::NodeInfo& info); } // namespace silkworm::sentry::grpc::interfaces diff --git a/silkworm/sentry/grpc/interfaces/peer_event.cpp b/silkworm/sentry/grpc/interfaces/peer_event.cpp index fe2b3aed90..a7cdb60b42 100644 --- a/silkworm/sentry/grpc/interfaces/peer_event.cpp +++ b/silkworm/sentry/grpc/interfaces/peer_event.cpp @@ -22,36 +22,36 @@ namespace silkworm::sentry::grpc::interfaces { namespace proto = ::sentry; -api::api_common::PeerEvent peer_event_from_proto_peer_event(const proto::PeerEvent& event) { - api::api_common::PeerEventId event_id; +api::PeerEvent peer_event_from_proto_peer_event(const proto::PeerEvent& event) { + api::PeerEventId event_id; switch (event.event_id()) { case proto::PeerEvent_PeerEventId_Connect: - event_id = api::api_common::PeerEventId::kAdded; + event_id = api::PeerEventId::kAdded; break; case proto::PeerEvent_PeerEventId_Disconnect: - event_id = api::api_common::PeerEventId::kRemoved; + event_id = api::PeerEventId::kRemoved; break; default: - event_id = api::api_common::PeerEventId::kRemoved; // Avoid -Wsometimes-uninitialized + event_id = api::PeerEventId::kRemoved; // Avoid -Wsometimes-uninitialized assert(false); } - return api::api_common::PeerEvent{ + return api::PeerEvent{ {peer_public_key_from_id(event.peer_id())}, event_id, }; } -proto::PeerEvent proto_peer_event_from_peer_event(const api::api_common::PeerEvent& event) { +proto::PeerEvent proto_peer_event_from_peer_event(const api::PeerEvent& event) { proto::PeerEvent reply; if (event.peer_public_key) { reply.mutable_peer_id()->CopyFrom(peer_id_from_public_key(event.peer_public_key.value())); } switch (event.event_id) { - case api::api_common::PeerEventId::kAdded: + case api::PeerEventId::kAdded: reply.set_event_id(proto::PeerEvent_PeerEventId_Connect); break; - case api::api_common::PeerEventId::kRemoved: + case api::PeerEventId::kRemoved: reply.set_event_id(proto::PeerEvent_PeerEventId_Disconnect); break; } diff --git a/silkworm/sentry/grpc/interfaces/peer_event.hpp b/silkworm/sentry/grpc/interfaces/peer_event.hpp index 8d4767fe15..64ccf05c68 100644 --- a/silkworm/sentry/grpc/interfaces/peer_event.hpp +++ b/silkworm/sentry/grpc/interfaces/peer_event.hpp @@ -17,11 +17,11 @@ #pragma once #include -#include +#include namespace silkworm::sentry::grpc::interfaces { -api::api_common::PeerEvent peer_event_from_proto_peer_event(const ::sentry::PeerEvent& event); -::sentry::PeerEvent proto_peer_event_from_peer_event(const api::api_common::PeerEvent& event); +api::PeerEvent peer_event_from_proto_peer_event(const ::sentry::PeerEvent& event); +::sentry::PeerEvent proto_peer_event_from_peer_event(const api::PeerEvent& event); } // namespace silkworm::sentry::grpc::interfaces diff --git a/silkworm/sentry/grpc/interfaces/peer_id.cpp b/silkworm/sentry/grpc/interfaces/peer_id.cpp index 386aa2e56e..5034c4ff95 100644 --- a/silkworm/sentry/grpc/interfaces/peer_id.cpp +++ b/silkworm/sentry/grpc/interfaces/peer_id.cpp @@ -22,15 +22,15 @@ namespace silkworm::sentry::grpc::interfaces { namespace proto_types = ::types; -sentry::common::EccPublicKey peer_public_key_from_id(const ::types::H512& peer_id) { - return sentry::common::EccPublicKey::deserialize(bytes_from_H512(peer_id)); +sentry::EccPublicKey peer_public_key_from_id(const ::types::H512& peer_id) { + return sentry::EccPublicKey::deserialize(bytes_from_H512(peer_id)); } -proto_types::H512 peer_id_from_public_key(const sentry::common::EccPublicKey& key) { +proto_types::H512 peer_id_from_public_key(const sentry::EccPublicKey& key) { return *H512_from_bytes(key.serialized()); } -std::string peer_id_string_from_public_key(const sentry::common::EccPublicKey& key) { +std::string peer_id_string_from_public_key(const sentry::EccPublicKey& key) { return key.hex(); } diff --git a/silkworm/sentry/grpc/interfaces/peer_id.hpp b/silkworm/sentry/grpc/interfaces/peer_id.hpp index 4f918185f3..3968846ea7 100644 --- a/silkworm/sentry/grpc/interfaces/peer_id.hpp +++ b/silkworm/sentry/grpc/interfaces/peer_id.hpp @@ -23,9 +23,9 @@ namespace silkworm::sentry::grpc::interfaces { -sentry::common::EccPublicKey peer_public_key_from_id(const ::types::H512& peer_id); -::types::H512 peer_id_from_public_key(const sentry::common::EccPublicKey& key); +sentry::EccPublicKey peer_public_key_from_id(const ::types::H512& peer_id); +::types::H512 peer_id_from_public_key(const sentry::EccPublicKey& key); -std::string peer_id_string_from_public_key(const sentry::common::EccPublicKey& key); +std::string peer_id_string_from_public_key(const sentry::EccPublicKey& key); } // namespace silkworm::sentry::grpc::interfaces diff --git a/silkworm/sentry/grpc/interfaces/peer_info.cpp b/silkworm/sentry/grpc/interfaces/peer_info.cpp index f94173916c..c36586624f 100644 --- a/silkworm/sentry/grpc/interfaces/peer_info.cpp +++ b/silkworm/sentry/grpc/interfaces/peer_info.cpp @@ -30,15 +30,15 @@ namespace silkworm::sentry::grpc::interfaces { boost::asio::ip::tcp::endpoint parse_endpoint(const std::string& address); -api::api_common::PeerInfo peer_info_from_proto_peer_info(const types::PeerInfo& info) { +api::PeerInfo peer_info_from_proto_peer_info(const types::PeerInfo& info) { std::vector capabilities; capabilities.reserve(static_cast(info.caps_size())); for (auto& cap : info.caps()) { capabilities.push_back(cap); } - return api::api_common::PeerInfo{ - sentry::common::EnodeUrl{info.enode()}, + return api::PeerInfo{ + sentry::EnodeUrl{info.enode()}, parse_endpoint(info.conn_local_addr()), parse_endpoint(info.conn_remote_addr()), info.conn_is_inbound(), @@ -48,7 +48,7 @@ api::api_common::PeerInfo peer_info_from_proto_peer_info(const types::PeerInfo& }; } -types::PeerInfo proto_peer_info_from_peer_info(const api::api_common::PeerInfo& peer) { +types::PeerInfo proto_peer_info_from_peer_info(const api::PeerInfo& peer) { types::PeerInfo info; info.set_id(peer_id_string_from_public_key(peer.url.public_key())); info.set_name(peer.client_id); @@ -75,15 +75,15 @@ types::PeerInfo proto_peer_info_from_peer_info(const api::api_common::PeerInfo& return info; } -api::api_common::PeerInfos peer_infos_from_proto_peers_reply(const ::sentry::PeersReply& reply) { - api::api_common::PeerInfos result; +api::PeerInfos peer_infos_from_proto_peers_reply(const ::sentry::PeersReply& reply) { + api::PeerInfos result; for (auto& peer : reply.peers()) { result.push_back(peer_info_from_proto_peer_info(peer)); } return result; } -::sentry::PeersReply proto_peers_reply_from_peer_infos(const api::api_common::PeerInfos& peers) { +::sentry::PeersReply proto_peers_reply_from_peer_infos(const api::PeerInfos& peers) { ::sentry::PeersReply reply; for (auto& peer : peers) { reply.add_peers()->CopyFrom(proto_peer_info_from_peer_info(peer)); @@ -91,7 +91,7 @@ ::sentry::PeersReply proto_peers_reply_from_peer_infos(const api::api_common::Pe return reply; } -std::optional peer_info_opt_from_proto_peer_reply(const ::sentry::PeerByIdReply& reply) { +std::optional peer_info_opt_from_proto_peer_reply(const ::sentry::PeerByIdReply& reply) { if (reply.has_peer()) { auto result = peer_info_from_proto_peer_info(reply.peer()); return {result}; @@ -100,7 +100,7 @@ std::optional peer_info_opt_from_proto_peer_reply(con } } -::sentry::PeerByIdReply proto_peer_reply_from_peer_info_opt(const std::optional& peer_opt) { +::sentry::PeerByIdReply proto_peer_reply_from_peer_info_opt(const std::optional& peer_opt) { ::sentry::PeerByIdReply reply; if (peer_opt) { reply.mutable_peer()->CopyFrom(proto_peer_info_from_peer_info(peer_opt.value())); diff --git a/silkworm/sentry/grpc/interfaces/peer_info.hpp b/silkworm/sentry/grpc/interfaces/peer_info.hpp index 4918a7ec4f..cbeb0ece64 100644 --- a/silkworm/sentry/grpc/interfaces/peer_info.hpp +++ b/silkworm/sentry/grpc/interfaces/peer_info.hpp @@ -20,17 +20,17 @@ #include #include -#include +#include namespace silkworm::sentry::grpc::interfaces { -api::api_common::PeerInfo peer_info_from_proto_peer_info(const types::PeerInfo& info); -types::PeerInfo proto_peer_info_from_peer_info(const api::api_common::PeerInfo& info); +api::PeerInfo peer_info_from_proto_peer_info(const types::PeerInfo& info); +types::PeerInfo proto_peer_info_from_peer_info(const api::PeerInfo& info); -api::api_common::PeerInfos peer_infos_from_proto_peers_reply(const ::sentry::PeersReply& reply); -::sentry::PeersReply proto_peers_reply_from_peer_infos(const api::api_common::PeerInfos& infos); +api::PeerInfos peer_infos_from_proto_peers_reply(const ::sentry::PeersReply& reply); +::sentry::PeersReply proto_peers_reply_from_peer_infos(const api::PeerInfos& infos); -std::optional peer_info_opt_from_proto_peer_reply(const ::sentry::PeerByIdReply& reply); -::sentry::PeerByIdReply proto_peer_reply_from_peer_info_opt(const std::optional& info_opt); +std::optional peer_info_opt_from_proto_peer_reply(const ::sentry::PeerByIdReply& reply); +::sentry::PeerByIdReply proto_peer_reply_from_peer_info_opt(const std::optional& info_opt); } // namespace silkworm::sentry::grpc::interfaces diff --git a/silkworm/sentry/grpc/interfaces/sent_peer_ids.cpp b/silkworm/sentry/grpc/interfaces/sent_peer_ids.cpp index 92282ac8ad..667c33870e 100644 --- a/silkworm/sentry/grpc/interfaces/sent_peer_ids.cpp +++ b/silkworm/sentry/grpc/interfaces/sent_peer_ids.cpp @@ -22,7 +22,7 @@ namespace silkworm::sentry::grpc::interfaces { namespace proto = ::sentry; -proto::SentPeers sent_peers_ids_from_peer_keys(const std::vector& keys) { +proto::SentPeers sent_peers_ids_from_peer_keys(const std::vector& keys) { proto::SentPeers result; for (auto& key : keys) { result.add_peers()->CopyFrom(peer_id_from_public_key(key)); @@ -30,8 +30,8 @@ proto::SentPeers sent_peers_ids_from_peer_keys(const std::vector peer_keys_from_sent_peers_ids(const proto::SentPeers& peer_ids) { - std::vector result; +std::vector peer_keys_from_sent_peers_ids(const proto::SentPeers& peer_ids) { + std::vector result; result.reserve(static_cast(peer_ids.peers_size())); for (auto& peer_id : peer_ids.peers()) { result.push_back(peer_public_key_from_id(peer_id)); diff --git a/silkworm/sentry/grpc/interfaces/sent_peer_ids.hpp b/silkworm/sentry/grpc/interfaces/sent_peer_ids.hpp index 4e7eb1ff88..8a7a577ab5 100644 --- a/silkworm/sentry/grpc/interfaces/sent_peer_ids.hpp +++ b/silkworm/sentry/grpc/interfaces/sent_peer_ids.hpp @@ -23,7 +23,7 @@ namespace silkworm::sentry::grpc::interfaces { -::sentry::SentPeers sent_peers_ids_from_peer_keys(const std::vector& keys); -std::vector peer_keys_from_sent_peers_ids(const ::sentry::SentPeers& peer_ids); +::sentry::SentPeers sent_peers_ids_from_peer_keys(const std::vector& keys); +std::vector peer_keys_from_sent_peers_ids(const ::sentry::SentPeers& peer_ids); } // namespace silkworm::sentry::grpc::interfaces diff --git a/silkworm/sentry/grpc/server/server_calls.hpp b/silkworm/sentry/grpc/server/server_calls.hpp index 9f39951941..656f69cea7 100644 --- a/silkworm/sentry/grpc/server/server_calls.hpp +++ b/silkworm/sentry/grpc/server/server_calls.hpp @@ -30,10 +30,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -102,7 +102,7 @@ class NodeInfoCall : public sw_rpc::server::UnaryCall do_send_message_call( const ServiceRouter& router, const proto::OutboundMessageData& request, - api::api_common::PeerFilter peer_filter) { + api::PeerFilter peer_filter) { auto message = interfaces::message_from_outbound_data(request); auto executor = co_await boost::asio::this_coro::executor; @@ -126,7 +126,7 @@ class SendMessageByIdCall : public sw_rpc::server::UnaryCall operator()(const ServiceRouter& router) { - proto::SentPeers reply = co_await do_send_message_call(router, request_, api::api_common::PeerFilter{}); + proto::SentPeers reply = co_await do_send_message_call(router, request_, api::PeerFilter{}); co_await agrpc::finish(responder_, reply, ::grpc::Status::OK); } }; @@ -166,7 +166,7 @@ class SendMessageByMinBlockCall : public sw_rpc::server::UnaryCall operator()(const ServiceRouter& router) { auto executor = co_await boost::asio::this_coro::executor; - auto call = std::make_shared>(executor); + auto call = std::make_shared>(executor); auto call_future = call->get_future(); co_await router.peers_calls_channel.send(call); diff --git a/silkworm/sentry/message_receiver.cpp b/silkworm/sentry/message_receiver.cpp index 00f8bee74e..ee8ef0e196 100644 --- a/silkworm/sentry/message_receiver.cpp +++ b/silkworm/sentry/message_receiver.cpp @@ -52,7 +52,7 @@ Task MessageReceiver::handle_calls() { while (true) { auto call = co_await message_calls_channel_.receive(); - auto messages_channel = std::make_shared>(executor); + auto messages_channel = std::make_shared>(executor); subscriptions_.push_back({ messages_channel, @@ -93,19 +93,19 @@ Task MessageReceiver::unsubscribe_on_signal(std::shared_ptr MessageReceiver::receive_messages(std::shared_ptr peer) { // loop until DisconnectedError while (true) { - common::Message message; + Message message; try { message = co_await peer->receive_message(); } catch (const rlpx::Peer::DisconnectedError& ex) { break; } - api::api_common::MessageFromPeer message_from_peer{ + api::MessageFromPeer message_from_peer{ std::move(message), {peer->peer_public_key()}, }; - std::list>> messages_channels; + std::list>> messages_channels; for (auto& subscription : subscriptions_) { if (subscription.message_id_filter.empty() || subscription.message_id_filter.contains(message_from_peer.message.id)) { messages_channels.push_back(subscription.messages_channel); diff --git a/silkworm/sentry/message_receiver.hpp b/silkworm/sentry/message_receiver.hpp index f592aa1b5a..85978c76e5 100644 --- a/silkworm/sentry/message_receiver.hpp +++ b/silkworm/sentry/message_receiver.hpp @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include #include #include "peer_manager.hpp" @@ -67,8 +67,8 @@ class MessageReceiver : public PeerManagerObserver { concurrency::TaskGroup unsubscription_tasks_; struct Subscription { - std::shared_ptr> messages_channel; - api::api_common::MessageIdSet message_id_filter; + std::shared_ptr> messages_channel; + api::MessageIdSet message_id_filter; std::shared_ptr unsubscribe_signal; }; diff --git a/silkworm/sentry/multi_sentry_client.cpp b/silkworm/sentry/multi_sentry_client.cpp index b2b5b38fcb..acb0318cc4 100644 --- a/silkworm/sentry/multi_sentry_client.cpp +++ b/silkworm/sentry/multi_sentry_client.cpp @@ -33,16 +33,16 @@ #include #include #include -#include +#include #include namespace silkworm::sentry { using namespace boost::asio; using namespace boost::asio::experimental; -using namespace api::api_common; +using namespace api; -class MultiSentryClientImpl : public api::api_common::Service { +class MultiSentryClientImpl : public api::Service { public: explicit MultiSentryClientImpl( std::vector> clients) @@ -53,7 +53,7 @@ class MultiSentryClientImpl : public api::api_common::Service { Task for_each_client( std::vector> clients, std::chrono::milliseconds timeout, - std::function(std::shared_ptr)> callback) { + std::function(std::shared_ptr)> callback) { using namespace concurrency::awaitable_wait_for_one; auto executor = co_await this_coro::executor; @@ -84,7 +84,7 @@ class MultiSentryClientImpl : public api::api_common::Service { } Task for_each_client( - std::function(std::shared_ptr)> callback) { + std::function(std::shared_ptr)> callback) { using namespace std::chrono_literals; auto clients = this->ready_clients(); @@ -125,7 +125,7 @@ class MultiSentryClientImpl : public api::api_common::Service { } // rpc SendMessageById(SendMessageByIdRequest) returns (SentPeers); - Task send_message_by_id(common::Message message, common::EccPublicKey public_key) override { + Task send_message_by_id(Message message, EccPublicKey public_key) override { PeerKeys all_peer_keys; std::mutex all_peer_keys_mutex; @@ -139,7 +139,7 @@ class MultiSentryClientImpl : public api::api_common::Service { } // rpc SendMessageToRandomPeers(SendMessageToRandomPeersRequest) returns (SentPeers); - Task send_message_to_random_peers(common::Message message, size_t max_peers) override { + Task send_message_to_random_peers(Message message, size_t max_peers) override { PeerKeys all_peer_keys; std::mutex all_peer_keys_mutex; @@ -153,7 +153,7 @@ class MultiSentryClientImpl : public api::api_common::Service { } // rpc SendMessageToAll(OutboundMessageData) returns (SentPeers); - Task send_message_to_all(common::Message message) override { + Task send_message_to_all(Message message) override { PeerKeys all_peer_keys; std::mutex all_peer_keys_mutex; @@ -167,7 +167,7 @@ class MultiSentryClientImpl : public api::api_common::Service { } // rpc SendMessageByMinBlock(SendMessageByMinBlockRequest) returns (SentPeers); - Task send_message_by_min_block(common::Message message, size_t max_peers) override { + Task send_message_by_min_block(Message message, size_t max_peers) override { PeerKeys all_peer_keys; std::mutex all_peer_keys_mutex; @@ -181,7 +181,7 @@ class MultiSentryClientImpl : public api::api_common::Service { } // rpc PeerMinBlock(PeerMinBlockRequest) returns (google.protobuf.Empty); - Task peer_min_block(common::EccPublicKey public_key) override { + Task peer_min_block(EccPublicKey public_key) override { co_await for_each_client([&public_key](auto service) -> Task { co_await service->peer_min_block(public_key); }); @@ -220,8 +220,8 @@ class MultiSentryClientImpl : public api::api_common::Service { } // rpc PeerById(PeerByIdRequest) returns (PeerByIdReply); - Task> peer_by_id(common::EccPublicKey public_key) override { - common::AtomicValue> found_peer{std::nullopt}; + Task> peer_by_id(EccPublicKey public_key) override { + AtomicValue> found_peer{std::nullopt}; co_await for_each_client([&public_key, &found_peer](auto service) -> Task { auto peer = co_await service->peer_by_id(public_key); if (peer) { @@ -232,7 +232,7 @@ class MultiSentryClientImpl : public api::api_common::Service { } // rpc PenalizePeer(PenalizePeerRequest) returns (google.protobuf.Empty); - Task penalize_peer(common::EccPublicKey public_key) override { + Task penalize_peer(EccPublicKey public_key) override { co_await for_each_client([&public_key](auto service) -> Task { co_await service->penalize_peer(public_key); }); @@ -271,7 +271,7 @@ MultiSentryClient::~MultiSentryClient() { [[maybe_unused]] int non_trivial_destructor; // silent clang-tidy } -Task> MultiSentryClient::service() { +Task> MultiSentryClient::service() { co_return p_impl_; } diff --git a/silkworm/sentry/multi_sentry_client.hpp b/silkworm/sentry/multi_sentry_client.hpp index eb5325d321..6d905b8a69 100644 --- a/silkworm/sentry/multi_sentry_client.hpp +++ b/silkworm/sentry/multi_sentry_client.hpp @@ -19,18 +19,18 @@ #include #include -#include +#include namespace silkworm::sentry { class MultiSentryClientImpl; -class MultiSentryClient : public api::api_common::SentryClient { +class MultiSentryClient : public api::SentryClient { public: - explicit MultiSentryClient(std::vector> clients); + explicit MultiSentryClient(std::vector> clients); ~MultiSentryClient() override; - Task> service() override; + Task> service() override; [[nodiscard]] bool is_ready() override; void on_disconnect(std::function()> callback) override; diff --git a/silkworm/sentry/nat/stun_ip_resolver.cpp b/silkworm/sentry/nat/stun_ip_resolver.cpp index ec71c2550d..fbadd9ca87 100644 --- a/silkworm/sentry/nat/stun_ip_resolver.cpp +++ b/silkworm/sentry/nat/stun_ip_resolver.cpp @@ -67,7 +67,7 @@ Task stun_ip_resolver() { int retry_count = 3; while (retry_count > 0) { try { - Bytes transaction_id = common::random_bytes(12); + Bytes transaction_id = random_bytes(12); stun::message binding_request{stun::message::binding_request, transaction_id.data()}; ByteView request_data(binding_request.data(), binding_request.size()); diff --git a/silkworm/sentry/node_key_config.cpp b/silkworm/sentry/node_key_config.cpp index 85822aa920..e731b25aa0 100644 --- a/silkworm/sentry/node_key_config.cpp +++ b/silkworm/sentry/node_key_config.cpp @@ -44,7 +44,7 @@ NodeKey NodeKeyConfig::load() const { if (!data) throw runtime_error("NodeKeyConfig::load failed to parse a hex string in the node key file"); - return common::EccKeyPair{data.value()}; + return EccKeyPair{data.value()}; } void NodeKeyConfig::save(const NodeKey& key) const { diff --git a/silkworm/sentry/node_key_config.hpp b/silkworm/sentry/node_key_config.hpp index fec9052c75..92570ef7f5 100644 --- a/silkworm/sentry/node_key_config.hpp +++ b/silkworm/sentry/node_key_config.hpp @@ -26,7 +26,7 @@ namespace silkworm::sentry { -using NodeKey = common::EccKeyPair; +using NodeKey = EccKeyPair; class NodeKeyConfig { public: diff --git a/silkworm/sentry/peer_manager.cpp b/silkworm/sentry/peer_manager.cpp index efc2561023..c72519dec5 100644 --- a/silkworm/sentry/peer_manager.cpp +++ b/silkworm/sentry/peer_manager.cpp @@ -55,7 +55,7 @@ Task PeerManager::start_in_strand(concurrency::Channel= max_peers_) { if (drop_peer_tasks_count_ < kMaxSimultaneousDropPeerTasks) { drop_peer_tasks_count_++; - drop_peer_tasks_.spawn(strand_, drop_peer(peer, rlpx::rlpx_common::DisconnectReason::TooManyPeers)); + drop_peer_tasks_.spawn(strand_, drop_peer(peer, rlpx::DisconnectReason::TooManyPeers)); } else { log::Warning("sentry") << "PeerManager::start_in_strand too many extra peers to disconnect gracefully, dropping a peer on the floor"; } @@ -100,7 +100,7 @@ Task PeerManager::wait_for_peer_handshake(std::shared_ptr peer Task PeerManager::drop_peer( std::shared_ptr peer, - rlpx::rlpx_common::DisconnectReason reason) { + rlpx::DisconnectReason reason) { auto _ = gsl::finally([this] { this->drop_peer_tasks_count_--; }); try { @@ -140,7 +140,7 @@ Task PeerManager::enumerate_peers_in_strand(EnumeratePeersCallback callbac } Task PeerManager::enumerate_random_peers_in_strand(size_t max_count, EnumeratePeersCallback callback) { - for (auto peer_ptr : common::random_list_items(peers_, max_count)) { + for (auto peer_ptr : random_list_items(peers_, max_count)) { callback(*peer_ptr); } co_return; @@ -175,8 +175,8 @@ void PeerManager::on_peer_removed(const std::shared_ptr& peer) { } } -std::vector PeerManager::peer_urls(const std::list>& peers) { - std::vector urls; +std::vector PeerManager::peer_urls(const std::list>& peers) { + std::vector urls; for (auto& peer : peers) { auto url_opt = peer->url(); if (url_opt) { @@ -212,7 +212,7 @@ Task PeerManager::discover_peers( } } -Task PeerManager::connect_peer(common::EnodeUrl peer_url, bool is_static_peer, std::unique_ptr client) { +Task PeerManager::connect_peer(EnodeUrl peer_url, bool is_static_peer, std::unique_ptr client) { auto _ = gsl::finally([this, peer_url] { this->connecting_peer_urls_.erase(peer_url); }); try { diff --git a/silkworm/sentry/peer_manager.hpp b/silkworm/sentry/peer_manager.hpp index af6b68207b..315f9b3db5 100644 --- a/silkworm/sentry/peer_manager.hpp +++ b/silkworm/sentry/peer_manager.hpp @@ -36,8 +36,8 @@ #include #include #include +#include #include -#include #include namespace silkworm::sentry { @@ -78,7 +78,7 @@ class PeerManager { Task wait_for_peer_handshake(std::shared_ptr peer); Task drop_peer( std::shared_ptr peer, - rlpx::rlpx_common::DisconnectReason reason); + rlpx::DisconnectReason reason); static constexpr size_t kMaxSimultaneousDropPeerTasks = 10; @@ -90,12 +90,12 @@ class PeerManager { void on_peer_added(const std::shared_ptr& peer); void on_peer_removed(const std::shared_ptr& peer); - static std::vector peer_urls(const std::list>& peers); + static std::vector peer_urls(const std::list>& peers); Task discover_peers( discovery::Discovery& discovery, std::function()> client_factory); Task connect_peer( - common::EnodeUrl peer_url, + EnodeUrl peer_url, bool is_static_peer, std::unique_ptr client); @@ -107,7 +107,7 @@ class PeerManager { concurrency::TaskGroup drop_peer_tasks_; size_t drop_peer_tasks_count_{0}; - std::set connecting_peer_urls_; + std::set connecting_peer_urls_; silkworm::rpc::ServerContextPool& context_pool_; concurrency::EventNotifier need_peers_notifier_; concurrency::TaskGroup connect_peer_tasks_; diff --git a/silkworm/sentry/peer_manager_api.cpp b/silkworm/sentry/peer_manager_api.cpp index df20f0d1a2..b03d49cf91 100644 --- a/silkworm/sentry/peer_manager_api.cpp +++ b/silkworm/sentry/peer_manager_api.cpp @@ -29,7 +29,7 @@ #include #include -#include +#include namespace silkworm::sentry { @@ -60,7 +60,7 @@ Task PeerManagerApi::handle_peer_count_calls() { } } -static std::optional make_peer_info(rlpx::Peer& peer) { +static std::optional make_peer_info(rlpx::Peer& peer) { auto url_opt = peer.url(); if (!url_opt) return std::nullopt; auto peer_public_key_opt = peer.peer_public_key(); @@ -74,7 +74,7 @@ static std::optional make_peer_info(rlpx::Peer& peer) capabilities.push_back(capability.to_string()); } - return api::api_common::PeerInfo{ + return api::PeerInfo{ url_opt.value(), peer.local_endpoint(), peer.remote_endpoint(), @@ -90,7 +90,7 @@ Task PeerManagerApi::handle_peers_calls() { while (true) { auto call = co_await peers_calls_channel_.receive(); - api::api_common::PeerInfos peers; + api::PeerInfos peers; co_await peer_manager_.enumerate_peers([&peers](std::shared_ptr peer) { auto info_opt = make_peer_info(*peer); if (info_opt) { @@ -108,7 +108,7 @@ Task PeerManagerApi::handle_peer_calls() { auto call = co_await peer_calls_channel_.receive(); auto peer_public_key_opt = call.peer_public_key; - std::optional info_opt; + std::optional info_opt; co_await peer_manager_.enumerate_peers([&info_opt, peer_public_key_opt](std::shared_ptr peer) { auto key_opt = peer->peer_public_key(); if (key_opt && peer_public_key_opt && (key_opt.value() == peer_public_key_opt.value())) { @@ -128,7 +128,7 @@ Task PeerManagerApi::handle_peer_penalize_calls() { co_await peer_manager_.enumerate_peers([peer_public_key_opt](std::shared_ptr peer) { auto key_opt = peer->peer_public_key(); if (key_opt && peer_public_key_opt && (key_opt.value() == peer_public_key_opt.value())) { - peer->disconnect(rlpx::rlpx_common::DisconnectReason::DisconnectRequested); + peer->disconnect(rlpx::DisconnectReason::DisconnectRequested); } }); } @@ -143,7 +143,7 @@ Task PeerManagerApi::handle_peer_events_calls() { log::Trace("sentry") << "PeerManagerApi::handle_peer_events_calls adding subscription"; - auto events_channel = std::make_shared>(executor); + auto events_channel = std::make_shared>(executor); events_subscriptions_.push_back({ events_channel, @@ -202,9 +202,9 @@ Task PeerManagerApi::forward_peer_events() { // PeerManagerObserver void PeerManagerApi::on_peer_added(std::shared_ptr peer) { - api::api_common::PeerEvent event{ + api::PeerEvent event{ peer->peer_public_key(), - api::api_common::PeerEventId::kAdded, + api::PeerEventId::kAdded, }; bool ok = peer_events_channel_.try_send(std::move(event)); if (!ok) { @@ -214,9 +214,9 @@ void PeerManagerApi::on_peer_added(std::shared_ptr peer) { // PeerManagerObserver void PeerManagerApi::on_peer_removed(std::shared_ptr peer) { - api::api_common::PeerEvent event{ + api::PeerEvent event{ peer->peer_public_key(), - api::api_common::PeerEventId::kRemoved, + api::PeerEventId::kRemoved, }; bool ok = peer_events_channel_.try_send(std::move(event)); if (!ok) { diff --git a/silkworm/sentry/peer_manager_api.hpp b/silkworm/sentry/peer_manager_api.hpp index 83bb7ff17e..7a2d2ed2d0 100644 --- a/silkworm/sentry/peer_manager_api.hpp +++ b/silkworm/sentry/peer_manager_api.hpp @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -64,7 +64,7 @@ class PeerManagerApi : public PeerManagerObserver { return peer_count_calls_channel_; } - Channel>>& peers_calls_channel() { + Channel>>& peers_calls_channel() { return peers_calls_channel_; } @@ -72,7 +72,7 @@ class PeerManagerApi : public PeerManagerObserver { return peer_calls_channel_; } - Channel>& peer_penalize_calls_channel() { + Channel>& peer_penalize_calls_channel() { return peer_penalize_calls_channel_; } @@ -96,20 +96,20 @@ class PeerManagerApi : public PeerManagerObserver { PeerManager& peer_manager_; Channel>> peer_count_calls_channel_; - Channel>> peers_calls_channel_; + Channel>> peers_calls_channel_; Channel peer_calls_channel_; - Channel> peer_penalize_calls_channel_; + Channel> peer_penalize_calls_channel_; Channel peer_events_calls_channel_; struct Subscription { - std::shared_ptr> events_channel; + std::shared_ptr> events_channel; std::shared_ptr unsubscribe_signal; }; std::list events_subscriptions_; boost::asio::strand strand_; concurrency::TaskGroup events_unsubscription_tasks_; - Channel peer_events_channel_; + Channel peer_events_channel_; }; } // namespace silkworm::sentry diff --git a/silkworm/sentry/rlpx/auth/auth_ack_message.cpp b/silkworm/sentry/rlpx/auth/auth_ack_message.cpp index 3e5c7825fb..e9c308230d 100644 --- a/silkworm/sentry/rlpx/auth/auth_ack_message.cpp +++ b/silkworm/sentry/rlpx/auth/auth_ack_message.cpp @@ -30,16 +30,16 @@ namespace silkworm::sentry::rlpx::auth { const uint8_t AuthAckMessage::version = 4; AuthAckMessage::AuthAckMessage( - common::EccPublicKey initiator_public_key, - common::EccPublicKey ephemeral_public_key) + EccPublicKey initiator_public_key, + EccPublicKey ephemeral_public_key) : initiator_public_key_(std::move(initiator_public_key)), ephemeral_public_key_(std::move(ephemeral_public_key)), - nonce_(common::random_bytes(32)) { + nonce_(random_bytes(32)) { } AuthAckMessage::AuthAckMessage( ByteView data, - const common::EccKeyPair& initiator_key_pair) + const EccKeyPair& initiator_key_pair) : initiator_public_key_(initiator_key_pair.public_key()), ephemeral_public_key_(Bytes{}) { init_from_rlp(AuthAckMessage::decrypt_body(data, initiator_key_pair.private_key())); @@ -57,7 +57,7 @@ void AuthAckMessage::init_from_rlp(ByteView data) { if (!result && (result.error() != DecodingError::kUnexpectedListElements)) { throw DecodingException(result.error(), "Failed to decode AuthAckMessage RLP"); } - ephemeral_public_key_ = common::EccPublicKey::deserialize(public_key_data); + ephemeral_public_key_ = EccPublicKey::deserialize(public_key_data); } Bytes AuthAckMessage::serialize_size(size_t body_size) { diff --git a/silkworm/sentry/rlpx/auth/auth_ack_message.hpp b/silkworm/sentry/rlpx/auth/auth_ack_message.hpp index 6ab17dcda5..834cd6cd3b 100644 --- a/silkworm/sentry/rlpx/auth/auth_ack_message.hpp +++ b/silkworm/sentry/rlpx/auth/auth_ack_message.hpp @@ -25,15 +25,15 @@ namespace silkworm::sentry::rlpx::auth { class AuthAckMessage { public: AuthAckMessage( - common::EccPublicKey initiator_public_key, - common::EccPublicKey ephemeral_public_key); + EccPublicKey initiator_public_key, + EccPublicKey ephemeral_public_key); AuthAckMessage( ByteView data, - const common::EccKeyPair& initiator_key_pair); + const EccKeyPair& initiator_key_pair); [[nodiscard]] Bytes serialize() const; - [[nodiscard]] const common::EccPublicKey& ephemeral_public_key() const { + [[nodiscard]] const EccPublicKey& ephemeral_public_key() const { return ephemeral_public_key_; } @@ -46,8 +46,8 @@ class AuthAckMessage { static Bytes serialize_size(size_t body_size); static Bytes decrypt_body(ByteView data, ByteView initiator_private_key); - common::EccPublicKey initiator_public_key_; - common::EccPublicKey ephemeral_public_key_; + EccPublicKey initiator_public_key_; + EccPublicKey ephemeral_public_key_; Bytes nonce_; static const uint8_t version; }; diff --git a/silkworm/sentry/rlpx/auth/auth_initiator.cpp b/silkworm/sentry/rlpx/auth/auth_initiator.cpp index 63f7398880..33b3f61526 100644 --- a/silkworm/sentry/rlpx/auth/auth_initiator.cpp +++ b/silkworm/sentry/rlpx/auth/auth_initiator.cpp @@ -28,7 +28,7 @@ namespace silkworm::sentry::rlpx::auth { using namespace std::chrono_literals; using namespace concurrency::awaitable_wait_for_one; -Task AuthInitiator::execute(common::SocketStream& stream) { +Task AuthInitiator::execute(SocketStream& stream) { AuthMessage auth_message{initiator_key_pair_, recipient_public_key_, initiator_ephemeral_key_pair_}; Bytes auth_data = auth_message.serialize(); co_await (stream.send(auth_data) || concurrency::timeout(5s)); diff --git a/silkworm/sentry/rlpx/auth/auth_initiator.hpp b/silkworm/sentry/rlpx/auth/auth_initiator.hpp index 39e9142323..2299924854 100644 --- a/silkworm/sentry/rlpx/auth/auth_initiator.hpp +++ b/silkworm/sentry/rlpx/auth/auth_initiator.hpp @@ -28,16 +28,16 @@ namespace silkworm::sentry::rlpx::auth { class AuthInitiator { public: - AuthInitiator(common::EccKeyPair initiator_key_pair, common::EccPublicKey recipient_public_key) + AuthInitiator(EccKeyPair initiator_key_pair, EccPublicKey recipient_public_key) : initiator_key_pair_(std::move(initiator_key_pair)), recipient_public_key_(std::move(recipient_public_key)) {} - Task execute(common::SocketStream& stream); + Task execute(SocketStream& stream); private: - common::EccKeyPair initiator_key_pair_; - common::EccPublicKey recipient_public_key_; - common::EccKeyPair initiator_ephemeral_key_pair_; + EccKeyPair initiator_key_pair_; + EccPublicKey recipient_public_key_; + EccKeyPair initiator_ephemeral_key_pair_; }; } // namespace silkworm::sentry::rlpx::auth diff --git a/silkworm/sentry/rlpx/auth/auth_keys.hpp b/silkworm/sentry/rlpx/auth/auth_keys.hpp index d01738af6e..3d40a66007 100644 --- a/silkworm/sentry/rlpx/auth/auth_keys.hpp +++ b/silkworm/sentry/rlpx/auth/auth_keys.hpp @@ -22,10 +22,10 @@ namespace silkworm::sentry::rlpx::auth { struct AuthKeys { - common::EccPublicKey peer_public_key; + EccPublicKey peer_public_key; - common::EccPublicKey peer_ephemeral_public_key; - common::EccKeyPair ephemeral_key_pair; + EccPublicKey peer_ephemeral_public_key; + EccKeyPair ephemeral_key_pair; Bytes initiator_nonce; Bytes recipient_nonce; diff --git a/silkworm/sentry/rlpx/auth/auth_message.cpp b/silkworm/sentry/rlpx/auth/auth_message.cpp index 9c4ee52cbf..48f8c5a5a2 100644 --- a/silkworm/sentry/rlpx/auth/auth_message.cpp +++ b/silkworm/sentry/rlpx/auth/auth_message.cpp @@ -30,20 +30,20 @@ namespace silkworm::sentry::rlpx::auth { -using namespace common::crypto::ecdsa_signature; +using namespace silkworm::sentry::crypto::ecdsa_signature; const uint8_t AuthMessage::version = 4; AuthMessage::AuthMessage( - const common::EccKeyPair& initiator_key_pair, - common::EccPublicKey recipient_public_key, - const common::EccKeyPair& ephemeral_key_pair) + const EccKeyPair& initiator_key_pair, + EccPublicKey recipient_public_key, + const EccKeyPair& ephemeral_key_pair) : initiator_public_key_(initiator_key_pair.public_key()), recipient_public_key_(std::move(recipient_public_key)), ephemeral_public_key_(ephemeral_key_pair.public_key()) { Bytes shared_secret = EciesCipher::compute_shared_secret(recipient_public_key_, initiator_key_pair.private_key()); - nonce_ = common::random_bytes(shared_secret.size()); + nonce_ = random_bytes(shared_secret.size()); // shared_secret ^= nonce_ crypto::xor_bytes(shared_secret, nonce_); @@ -51,7 +51,7 @@ AuthMessage::AuthMessage( signature_ = sign(shared_secret, ephemeral_key_pair.private_key()); } -AuthMessage::AuthMessage(ByteView data, const common::EccKeyPair& recipient_key_pair) +AuthMessage::AuthMessage(ByteView data, const EccKeyPair& recipient_key_pair) : initiator_public_key_(Bytes{}), recipient_public_key_(recipient_key_pair.public_key()), ephemeral_public_key_(Bytes{}) { @@ -81,7 +81,7 @@ void AuthMessage::init_from_rlp(ByteView data) { if (!result && (result.error() != DecodingError::kUnexpectedListElements)) { throw DecodingException(result.error(), "Failed to decode AuthMessage RLP"); } - initiator_public_key_ = common::EccPublicKey::deserialize(public_key_data); + initiator_public_key_ = EccPublicKey::deserialize(public_key_data); } Bytes AuthMessage::serialize_size(size_t body_size) { diff --git a/silkworm/sentry/rlpx/auth/auth_message.hpp b/silkworm/sentry/rlpx/auth/auth_message.hpp index 2c6d39c50e..0a2a623385 100644 --- a/silkworm/sentry/rlpx/auth/auth_message.hpp +++ b/silkworm/sentry/rlpx/auth/auth_message.hpp @@ -25,18 +25,18 @@ namespace silkworm::sentry::rlpx::auth { class AuthMessage { public: AuthMessage( - const common::EccKeyPair& initiator_key_pair, - common::EccPublicKey recipient_public_key, - const common::EccKeyPair& ephemeral_key_pair); - AuthMessage(ByteView data, const common::EccKeyPair& recipient_key_pair); + const EccKeyPair& initiator_key_pair, + EccPublicKey recipient_public_key, + const EccKeyPair& ephemeral_key_pair); + AuthMessage(ByteView data, const EccKeyPair& recipient_key_pair); [[nodiscard]] Bytes serialize() const; - [[nodiscard]] const common::EccPublicKey& initiator_public_key() const { + [[nodiscard]] const EccPublicKey& initiator_public_key() const { return initiator_public_key_; } - [[nodiscard]] const common::EccPublicKey& ephemeral_public_key() const { + [[nodiscard]] const EccPublicKey& ephemeral_public_key() const { return ephemeral_public_key_; } @@ -49,9 +49,9 @@ class AuthMessage { static Bytes serialize_size(size_t body_size); static Bytes decrypt_body(ByteView data, ByteView recipient_private_key); - common::EccPublicKey initiator_public_key_; - common::EccPublicKey recipient_public_key_; - common::EccPublicKey ephemeral_public_key_; + EccPublicKey initiator_public_key_; + EccPublicKey recipient_public_key_; + EccPublicKey ephemeral_public_key_; Bytes nonce_; Bytes signature_; static const uint8_t version; diff --git a/silkworm/sentry/rlpx/auth/auth_recipient.cpp b/silkworm/sentry/rlpx/auth/auth_recipient.cpp index 7a28f8db7a..e455ac03dc 100644 --- a/silkworm/sentry/rlpx/auth/auth_recipient.cpp +++ b/silkworm/sentry/rlpx/auth/auth_recipient.cpp @@ -28,7 +28,7 @@ namespace silkworm::sentry::rlpx::auth { using namespace std::chrono_literals; using namespace concurrency::awaitable_wait_for_one; -Task AuthRecipient::execute(common::SocketStream& stream) { +Task AuthRecipient::execute(SocketStream& stream) { Bytes auth_data_raw; auto auth_data = std::get(co_await (stream.receive_size_and_data(auth_data_raw) || concurrency::timeout(5s))); AuthMessage auth_message{auth_data, recipient_key_pair_}; diff --git a/silkworm/sentry/rlpx/auth/auth_recipient.hpp b/silkworm/sentry/rlpx/auth/auth_recipient.hpp index c52b1b623a..94a68c224e 100644 --- a/silkworm/sentry/rlpx/auth/auth_recipient.hpp +++ b/silkworm/sentry/rlpx/auth/auth_recipient.hpp @@ -28,14 +28,14 @@ namespace silkworm::sentry::rlpx::auth { class AuthRecipient { public: - explicit AuthRecipient(common::EccKeyPair recipient_key_pair) + explicit AuthRecipient(EccKeyPair recipient_key_pair) : recipient_key_pair_(std::move(recipient_key_pair)) {} - Task execute(common::SocketStream& stream); + Task execute(SocketStream& stream); private: - common::EccKeyPair recipient_key_pair_; - common::EccKeyPair recipient_ephemeral_key_pair_; + EccKeyPair recipient_key_pair_; + EccKeyPair recipient_ephemeral_key_pair_; }; } // namespace silkworm::sentry::rlpx::auth diff --git a/silkworm/sentry/rlpx/auth/ecies_cipher.cpp b/silkworm/sentry/rlpx/auth/ecies_cipher.cpp index a8c549c980..dde5623366 100644 --- a/silkworm/sentry/rlpx/auth/ecies_cipher.cpp +++ b/silkworm/sentry/rlpx/auth/ecies_cipher.cpp @@ -54,7 +54,7 @@ EciesCipher::Message EciesCipher::encrypt_message( ByteView plain_text, PublicKeyView public_key_view, ByteView mac_extra_data) { - common::EccKeyPair ephemeral_key_pair; + EccKeyPair ephemeral_key_pair; Bytes shared_secret = kdf(compute_shared_secret(public_key_view, ephemeral_key_pair.private_key())); ByteView aes_key(shared_secret.data(), kKeySize); @@ -144,7 +144,7 @@ EciesCipher::Message EciesCipher::deserialize_message(ByteView message_data) { Bytes cipher_text{&message_data[key_size + iv_size], cipher_text_size}; Bytes mac{&message_data[key_size + iv_size + cipher_text_size], mac_size}; - auto ephemeral_public_key = common::EccPublicKey::deserialize_std(key_data); + auto ephemeral_public_key = EccPublicKey::deserialize_std(key_data); return { std::move(ephemeral_public_key), diff --git a/silkworm/sentry/rlpx/auth/ecies_cipher.hpp b/silkworm/sentry/rlpx/auth/ecies_cipher.hpp index b1d554ae75..b61522b771 100644 --- a/silkworm/sentry/rlpx/auth/ecies_cipher.hpp +++ b/silkworm/sentry/rlpx/auth/ecies_cipher.hpp @@ -23,7 +23,7 @@ namespace silkworm::sentry::rlpx::auth { class EciesCipher { public: - using PublicKey = common::EccPublicKey; + using PublicKey = EccPublicKey; using PublicKeyView = const PublicKey&; using PrivateKeyView = ByteView; diff --git a/silkworm/sentry/rlpx/auth/ecies_cipher_test.cpp b/silkworm/sentry/rlpx/auth/ecies_cipher_test.cpp index 9fb1c0c3b2..6014d4e38d 100644 --- a/silkworm/sentry/rlpx/auth/ecies_cipher_test.cpp +++ b/silkworm/sentry/rlpx/auth/ecies_cipher_test.cpp @@ -25,7 +25,7 @@ namespace silkworm::sentry::rlpx::auth { TEST_CASE("EciesCipher.encrypt_decrypt_message") { - common::EccKeyPair receiver_key; + EccKeyPair receiver_key; Bytes expected_plain_text = {1, 2, 3, 4, 5}; expected_plain_text.resize(crypto::kAESBlockSize); @@ -43,7 +43,7 @@ TEST_CASE("EciesCipher.encrypt_decrypt_message") { } TEST_CASE("EciesCipher.encrypt_decrypt_bytes") { - common::EccKeyPair receiver_key; + EccKeyPair receiver_key; Bytes expected_plain_text = {1, 2, 3, 4, 5}; expected_plain_text.resize(crypto::kAESBlockSize); diff --git a/silkworm/sentry/rlpx/auth/handshake.cpp b/silkworm/sentry/rlpx/auth/handshake.cpp index be89c00142..b3142a8579 100644 --- a/silkworm/sentry/rlpx/auth/handshake.cpp +++ b/silkworm/sentry/rlpx/auth/handshake.cpp @@ -19,8 +19,8 @@ #include #include #include +#include #include -#include #include "auth_initiator.hpp" #include "auth_recipient.hpp" @@ -30,9 +30,8 @@ namespace silkworm::sentry::rlpx::auth { using namespace std::chrono_literals; using namespace concurrency::awaitable_wait_for_one; -using common::Message; -Task Handshake::auth(common::SocketStream& stream) { +Task Handshake::auth(SocketStream& stream) { if (peer_public_key_) { auth::AuthInitiator auth_initiator{node_key_, peer_public_key_.value()}; co_return (co_await auth_initiator.execute(stream)); @@ -42,7 +41,7 @@ Task Handshake::auth(common::SocketStream& stream) { } } -Task Handshake::execute(common::SocketStream& stream) { +Task Handshake::execute(SocketStream& stream) { auto auth_keys = co_await auth(stream); log::Debug("sentry") << "rlpx::auth::Handshake AuthKeys.peer_ephemeral_public_key: " << auth_keys.peer_ephemeral_public_key.hex(); @@ -73,7 +72,7 @@ Task Handshake::execute(common::SocketStream& stream Message reply_message = std::get(co_await (message_stream.receive() || concurrency::timeout(5s))); if (reply_message.id != HelloMessage::kId) { - if (reply_message.id == rlpx_common::DisconnectMessage::kId) { + if (reply_message.id == DisconnectMessage::kId) { throw DisconnectError(); } else { throw std::runtime_error("rlpx::auth::Handshake: unexpected RLPx message"); diff --git a/silkworm/sentry/rlpx/auth/handshake.hpp b/silkworm/sentry/rlpx/auth/handshake.hpp index 0129a837ee..23d4690879 100644 --- a/silkworm/sentry/rlpx/auth/handshake.hpp +++ b/silkworm/sentry/rlpx/auth/handshake.hpp @@ -36,11 +36,11 @@ namespace silkworm::sentry::rlpx::auth { class Handshake { public: explicit Handshake( - common::EccKeyPair node_key, + EccKeyPair node_key, std::string client_id, uint16_t node_listen_port, std::pair required_capability, - std::optional peer_public_key) + std::optional peer_public_key) : node_key_(std::move(node_key)), client_id_(std::move(client_id)), node_listen_port_(node_listen_port), @@ -50,11 +50,11 @@ class Handshake { struct HandshakeResult { framing::MessageStream message_stream; - common::EccPublicKey peer_public_key; + EccPublicKey peer_public_key; HelloMessage hello_reply_message; }; - Task execute(common::SocketStream& stream); + Task execute(SocketStream& stream); class DisconnectError : public std::runtime_error { public: @@ -62,14 +62,14 @@ class Handshake { }; private: - Task auth(common::SocketStream& stream); + Task auth(SocketStream& stream); - common::EccKeyPair node_key_; + EccKeyPair node_key_; std::string client_id_; uint16_t node_listen_port_; std::pair required_capability_; const bool is_initiator_; - std::optional peer_public_key_; + std::optional peer_public_key_; }; } // namespace silkworm::sentry::rlpx::auth diff --git a/silkworm/sentry/rlpx/auth/hello_message.cpp b/silkworm/sentry/rlpx/auth/hello_message.cpp index 9fa2d74f12..4f4619cd48 100644 --- a/silkworm/sentry/rlpx/auth/hello_message.cpp +++ b/silkworm/sentry/rlpx/auth/hello_message.cpp @@ -26,8 +26,6 @@ namespace silkworm::sentry::rlpx::auth { -using common::Message; - const uint8_t HelloMessage::kId = 0; const uint8_t HelloMessage::kProtocolVersion = 5; diff --git a/silkworm/sentry/rlpx/auth/hello_message.hpp b/silkworm/sentry/rlpx/auth/hello_message.hpp index ffc8b2446a..2d1dd2c22a 100644 --- a/silkworm/sentry/rlpx/auth/hello_message.hpp +++ b/silkworm/sentry/rlpx/auth/hello_message.hpp @@ -57,7 +57,7 @@ class HelloMessage { std::string_view client_id, std::vector capabilities, uint16_t listen_port, - const common::EccPublicKey& node_id) + const EccPublicKey& node_id) : client_id_bytes_(reinterpret_cast(client_id.data()), client_id.size()), capabilities_(std::move(capabilities)), listen_port_(listen_port), @@ -75,15 +75,15 @@ class HelloMessage { [[nodiscard]] uint16_t listen_port() const { return listen_port_; } - [[nodiscard]] common::EccPublicKey node_id() const { - return common::EccPublicKey::deserialize(node_id_bytes_); + [[nodiscard]] EccPublicKey node_id() const { + return EccPublicKey::deserialize(node_id_bytes_); } [[nodiscard]] Bytes rlp_encode() const; [[nodiscard]] static HelloMessage rlp_decode(ByteView data); - [[nodiscard]] common::Message to_message() const; - [[nodiscard]] static HelloMessage from_message(const common::Message& message); + [[nodiscard]] Message to_message() const; + [[nodiscard]] static HelloMessage from_message(const Message& message); static const uint8_t kId; static const uint8_t kProtocolVersion; diff --git a/silkworm/sentry/rlpx/client.cpp b/silkworm/sentry/rlpx/client.cpp index 966824e486..166a35a28c 100644 --- a/silkworm/sentry/rlpx/client.cpp +++ b/silkworm/sentry/rlpx/client.cpp @@ -32,7 +32,7 @@ using namespace std::chrono_literals; using namespace boost::asio; Task> Client::connect( - common::EnodeUrl peer_url, + EnodeUrl peer_url, bool is_static_peer) { log::Debug("sentry") << "rlpx::Client connecting to " << peer_url.to_string(); @@ -45,7 +45,7 @@ Task> Client::connect( use_awaitable); const ip::tcp::endpoint& endpoint = *endpoints.cbegin(); - common::SocketStream stream{client_context}; + SocketStream stream{client_context}; bool is_connected = false; while (!is_connected) { @@ -61,8 +61,8 @@ Task> Client::connect( << ", reconnecting..."; } if (!is_connected) { - stream = common::SocketStream{client_context}; - co_await common::sleep(10s); + stream = SocketStream{client_context}; + co_await sleep(10s); } } diff --git a/silkworm/sentry/rlpx/client.hpp b/silkworm/sentry/rlpx/client.hpp index e0f35859b1..d5f08709fc 100644 --- a/silkworm/sentry/rlpx/client.hpp +++ b/silkworm/sentry/rlpx/client.hpp @@ -33,7 +33,7 @@ namespace silkworm::sentry::rlpx { class Client { public: Client( - common::EccKeyPair node_key, + EccKeyPair node_key, std::string client_id, uint16_t node_listen_port, std::function()> protocol_factory) @@ -44,11 +44,11 @@ class Client { } Task> connect( - common::EnodeUrl peer_url, + EnodeUrl peer_url, bool is_static_peer); private: - common::EccKeyPair node_key_; + EccKeyPair node_key_; std::string client_id_; uint16_t node_listen_port_; std::function()> protocol_factory_; diff --git a/silkworm/sentry/rlpx/rlpx_common/disconnect_message.cpp b/silkworm/sentry/rlpx/common/disconnect_message.cpp similarity index 92% rename from silkworm/sentry/rlpx/rlpx_common/disconnect_message.cpp rename to silkworm/sentry/rlpx/common/disconnect_message.cpp index d917719643..8303845866 100644 --- a/silkworm/sentry/rlpx/rlpx_common/disconnect_message.cpp +++ b/silkworm/sentry/rlpx/common/disconnect_message.cpp @@ -23,9 +23,9 @@ #include #include -namespace silkworm::sentry::rlpx::rlpx_common { +namespace silkworm::sentry::rlpx { -using sentry::common::Message; +using sentry::Message; const uint8_t DisconnectMessage::kId = 1; @@ -53,4 +53,4 @@ DisconnectMessage DisconnectMessage::from_message(const Message& message) { return rlp_decode(message.data); } -} // namespace silkworm::sentry::rlpx::rlpx_common +} // namespace silkworm::sentry::rlpx diff --git a/silkworm/sentry/rlpx/rlpx_common/disconnect_message.hpp b/silkworm/sentry/rlpx/common/disconnect_message.hpp similarity index 84% rename from silkworm/sentry/rlpx/rlpx_common/disconnect_message.hpp rename to silkworm/sentry/rlpx/common/disconnect_message.hpp index 1d50ed5ced..bbc66f57bb 100644 --- a/silkworm/sentry/rlpx/rlpx_common/disconnect_message.hpp +++ b/silkworm/sentry/rlpx/common/disconnect_message.hpp @@ -21,17 +21,17 @@ #include "disconnect_reason.hpp" -namespace silkworm::sentry::rlpx::rlpx_common { +namespace silkworm::sentry::rlpx { struct DisconnectMessage { [[nodiscard]] Bytes rlp_encode() const; [[nodiscard]] static DisconnectMessage rlp_decode(ByteView data); - [[nodiscard]] sentry::common::Message to_message() const; - [[nodiscard]] static DisconnectMessage from_message(const sentry::common::Message& message); + [[nodiscard]] sentry::Message to_message() const; + [[nodiscard]] static DisconnectMessage from_message(const sentry::Message& message); static const uint8_t kId; DisconnectReason reason{DisconnectReason::DisconnectRequested}; }; -} // namespace silkworm::sentry::rlpx::rlpx_common +} // namespace silkworm::sentry::rlpx diff --git a/silkworm/sentry/rlpx/rlpx_common/disconnect_reason.hpp b/silkworm/sentry/rlpx/common/disconnect_reason.hpp similarity index 88% rename from silkworm/sentry/rlpx/rlpx_common/disconnect_reason.hpp rename to silkworm/sentry/rlpx/common/disconnect_reason.hpp index 3cae82e962..40d00711fa 100644 --- a/silkworm/sentry/rlpx/rlpx_common/disconnect_reason.hpp +++ b/silkworm/sentry/rlpx/common/disconnect_reason.hpp @@ -18,7 +18,7 @@ #include -namespace silkworm::sentry::rlpx::rlpx_common { +namespace silkworm::sentry::rlpx { enum class DisconnectReason : uint8_t { DisconnectRequested = 0, @@ -28,4 +28,4 @@ enum class DisconnectReason : uint8_t { PingTimeout = 11, }; -} // namespace silkworm::sentry::rlpx::rlpx_common +} // namespace silkworm::sentry::rlpx diff --git a/silkworm/sentry/rlpx/crypto/aes.cpp b/silkworm/sentry/rlpx/crypto/aes.cpp index c9f367c3c3..609a401548 100644 --- a/silkworm/sentry/rlpx/crypto/aes.cpp +++ b/silkworm/sentry/rlpx/crypto/aes.cpp @@ -116,7 +116,7 @@ Bytes aes_decrypt(ByteView cipher_text, ByteView key, ByteView iv) { } Bytes aes_make_iv() { - return common::random_bytes(AES_BLOCK_SIZE); + return random_bytes(AES_BLOCK_SIZE); } size_t aes_round_up_to_block_size(size_t size) { diff --git a/silkworm/sentry/rlpx/framing/message_frame_codec.cpp b/silkworm/sentry/rlpx/framing/message_frame_codec.cpp index 7dd53474b8..cf2e48e3ca 100644 --- a/silkworm/sentry/rlpx/framing/message_frame_codec.cpp +++ b/silkworm/sentry/rlpx/framing/message_frame_codec.cpp @@ -27,8 +27,6 @@ namespace silkworm::sentry::rlpx::framing { -using common::Message; - const size_t MessageFrameCodec::kMaxFrameSize = 16 << 20; static Bytes snappy_compress(ByteView data) { diff --git a/silkworm/sentry/rlpx/framing/message_frame_codec.hpp b/silkworm/sentry/rlpx/framing/message_frame_codec.hpp index 7b348d95ea..beb6655048 100644 --- a/silkworm/sentry/rlpx/framing/message_frame_codec.hpp +++ b/silkworm/sentry/rlpx/framing/message_frame_codec.hpp @@ -22,8 +22,8 @@ namespace silkworm::sentry::rlpx::framing { class MessageFrameCodec { public: - [[nodiscard]] Bytes encode(const common::Message& message) const; - [[nodiscard]] common::Message decode(ByteView frame_data) const; + [[nodiscard]] Bytes encode(const Message& message) const; + [[nodiscard]] Message decode(ByteView frame_data) const; void enable_compression() { is_compression_enabled_ = true; } diff --git a/silkworm/sentry/rlpx/framing/message_stream.cpp b/silkworm/sentry/rlpx/framing/message_stream.cpp index c76c8b2895..ed140c7e4f 100644 --- a/silkworm/sentry/rlpx/framing/message_stream.cpp +++ b/silkworm/sentry/rlpx/framing/message_stream.cpp @@ -22,11 +22,11 @@ namespace silkworm::sentry::rlpx::framing { -Task MessageStream::send(common::Message message) { +Task MessageStream::send(Message message) { co_await stream_.send(cipher_.encrypt_frame(message_frame_codec_.encode(message))); } -Task MessageStream::receive() { +Task MessageStream::receive() { Bytes header_data = co_await stream_.receive_fixed(FramingCipher::header_size()); size_t header_frame_size = cipher_.decrypt_header(header_data); diff --git a/silkworm/sentry/rlpx/framing/message_stream.hpp b/silkworm/sentry/rlpx/framing/message_stream.hpp index 72cbb47e55..d6c3c887b7 100644 --- a/silkworm/sentry/rlpx/framing/message_stream.hpp +++ b/silkworm/sentry/rlpx/framing/message_stream.hpp @@ -28,20 +28,20 @@ namespace silkworm::sentry::rlpx::framing { class MessageStream { public: - MessageStream(FramingCipher cipher, common::SocketStream& stream) + MessageStream(FramingCipher cipher, SocketStream& stream) : cipher_(std::move(cipher)), stream_(stream) {} MessageStream(MessageStream&&) = default; - Task send(common::Message message); - Task receive(); + Task send(Message message); + Task receive(); void enable_compression(); private: FramingCipher cipher_; - common::SocketStream& stream_; + SocketStream& stream_; MessageFrameCodec message_frame_codec_; }; diff --git a/silkworm/sentry/rlpx/peer.cpp b/silkworm/sentry/rlpx/peer.cpp index bfe502a3f1..2d9ebd34ea 100644 --- a/silkworm/sentry/rlpx/peer.cpp +++ b/silkworm/sentry/rlpx/peer.cpp @@ -31,24 +31,23 @@ #include #include "auth/handshake.hpp" +#include "common/disconnect_message.hpp" #include "ping_message.hpp" -#include "rlpx_common/disconnect_message.hpp" namespace silkworm::sentry::rlpx { using namespace std::chrono_literals; using namespace boost::asio; -using namespace rlpx_common; Peer::Peer( any_io_executor&& executor, - common::SocketStream stream, - common::EccKeyPair node_key, + SocketStream stream, + EccKeyPair node_key, std::string client_id, uint16_t node_listen_port, std::unique_ptr protocol, - std::optional url, - std::optional peer_public_key, + std::optional url, + std::optional peer_public_key, bool is_inbound, bool is_static) : stream_(std::move(stream)), @@ -271,7 +270,7 @@ void Peer::close() { } } -void Peer::post_message(const std::shared_ptr& peer, const common::Message& message) { +void Peer::post_message(const std::shared_ptr& peer, const Message& message) { peer->send_message_tasks_.spawn(peer->strand_, Peer::send_message(peer, message)); } @@ -279,7 +278,7 @@ Task Peer::send_message_tasks_wait(std::shared_ptr self) { co_await self->send_message_tasks_.wait(); } -Task Peer::send_message(std::shared_ptr peer, common::Message message) { +Task Peer::send_message(std::shared_ptr peer, Message message) { try { co_await peer->send_message(std::move(message)); } catch (const DisconnectedError& ex) { @@ -297,7 +296,7 @@ Task Peer::send_message(std::shared_ptr peer, common::Message messag } } -Task Peer::send_message(common::Message message) { +Task Peer::send_message(Message message) { try { co_await send_message_channel_.send(std::move(message)); } catch (const boost::system::system_error& ex) { @@ -310,7 +309,7 @@ Task Peer::send_message(common::Message message) { Task Peer::send_messages(framing::MessageStream& message_stream) { // loop until message_stream exception while (true) { - common::Message message; + Message message; try { message = co_await send_message_channel_.receive(); } catch (const boost::system::system_error& ex) { @@ -322,7 +321,7 @@ Task Peer::send_messages(framing::MessageStream& message_stream) { } } -Task Peer::receive_message() { +Task Peer::receive_message() { try { co_return (co_await receive_message_channel_.receive()); } catch (const boost::system::system_error& ex) { @@ -368,7 +367,7 @@ Task Peer::ping_periodically(framing::MessageStream& message_stream) { // loop until message_stream exception while (true) { - co_await common::sleep(kPeerPingInterval); + co_await sleep(kPeerPingInterval); co_await message_stream.send(PingMessage{}.to_message()); diff --git a/silkworm/sentry/rlpx/peer.hpp b/silkworm/sentry/rlpx/peer.hpp index 186f3b85e5..cd266d6de6 100644 --- a/silkworm/sentry/rlpx/peer.hpp +++ b/silkworm/sentry/rlpx/peer.hpp @@ -38,9 +38,9 @@ #include #include "auth/hello_message.hpp" +#include "common/disconnect_reason.hpp" #include "framing/message_stream.hpp" #include "protocol.hpp" -#include "rlpx_common/disconnect_reason.hpp" namespace silkworm::sentry::rlpx { @@ -48,25 +48,25 @@ class Peer { public: Peer( boost::asio::any_io_executor&& executor, - common::SocketStream stream, - common::EccKeyPair node_key, + SocketStream stream, + EccKeyPair node_key, std::string client_id, uint16_t node_listen_port, std::unique_ptr protocol, - std::optional url, - std::optional peer_public_key, + std::optional url, + std::optional peer_public_key, bool is_inbound, bool is_static); Peer( boost::asio::any_io_executor& executor, - common::SocketStream stream, - common::EccKeyPair node_key, + SocketStream stream, + EccKeyPair node_key, std::string client_id, uint16_t node_listen_port, std::unique_ptr protocol, - std::optional url, - std::optional peer_public_key, + std::optional url, + std::optional peer_public_key, bool is_inbound, bool is_static) : Peer( @@ -83,13 +83,13 @@ class Peer { Peer( boost::asio::io_context& io_context, - common::SocketStream stream, - common::EccKeyPair node_key, + SocketStream stream, + EccKeyPair node_key, std::string client_id, uint16_t node_listen_port, std::unique_ptr protocol, - std::optional url, - std::optional peer_public_key, + std::optional url, + std::optional peer_public_key, bool is_inbound, bool is_static) : Peer( @@ -107,23 +107,23 @@ class Peer { ~Peer(); static Task start(std::shared_ptr peer); - static Task drop(const std::shared_ptr& peer, rlpx_common::DisconnectReason reason); - void disconnect(rlpx_common::DisconnectReason reason); + static Task drop(const std::shared_ptr& peer, DisconnectReason reason); + void disconnect(DisconnectReason reason); static Task wait_for_handshake(std::shared_ptr self); - static void post_message(const std::shared_ptr& peer, const common::Message& message); - Task receive_message(); + static void post_message(const std::shared_ptr& peer, const Message& message); + Task receive_message(); class DisconnectedError : public std::runtime_error { public: DisconnectedError() : std::runtime_error("rlpx::Peer is disconnected") {} }; - std::optional url() { + std::optional url() { return url_.get(); } - std::optional peer_public_key() { + std::optional peer_public_key() { return peer_public_key_.get(); } @@ -145,37 +145,37 @@ class Peer { private: static Task handle(std::shared_ptr peer); Task handle(); - static Task drop_in_strand(std::shared_ptr peer, rlpx_common::DisconnectReason reason); - Task drop(rlpx_common::DisconnectReason reason); + static Task drop_in_strand(std::shared_ptr peer, DisconnectReason reason); + Task drop(DisconnectReason reason); Task handshake(); void close(); static Task send_message_tasks_wait(std::shared_ptr self); - static Task send_message(std::shared_ptr peer, common::Message message); - Task send_message(common::Message message); + static Task send_message(std::shared_ptr peer, Message message); + Task send_message(Message message); Task send_messages(framing::MessageStream& message_stream); Task receive_messages(framing::MessageStream& message_stream); Task ping_periodically(framing::MessageStream& message_stream); - common::SocketStream stream_; - common::EccKeyPair node_key_; + SocketStream stream_; + EccKeyPair node_key_; std::string client_id_; uint16_t node_listen_port_; std::unique_ptr protocol_; - common::AtomicValue> url_; - common::AtomicValue> peer_public_key_; + AtomicValue> url_; + AtomicValue> peer_public_key_; bool is_inbound_; bool is_static_; - common::AtomicValue> hello_message_{std::nullopt}; + AtomicValue> hello_message_{std::nullopt}; concurrency::AwaitablePromise handshake_promise_; - common::AtomicValue> disconnect_reason_{std::nullopt}; + AtomicValue> disconnect_reason_{std::nullopt}; boost::asio::strand strand_; concurrency::TaskGroup send_message_tasks_; - concurrency::Channel send_message_channel_; - concurrency::Channel receive_message_channel_; - concurrency::Channel pong_channel_; + concurrency::Channel send_message_channel_; + concurrency::Channel receive_message_channel_; + concurrency::Channel pong_channel_; }; } // namespace silkworm::sentry::rlpx diff --git a/silkworm/sentry/rlpx/ping_message.cpp b/silkworm/sentry/rlpx/ping_message.cpp index a080925645..b90ed339d8 100644 --- a/silkworm/sentry/rlpx/ping_message.cpp +++ b/silkworm/sentry/rlpx/ping_message.cpp @@ -35,12 +35,12 @@ Bytes PongMessage::rlp_encode() const { return data; } -sentry::common::Message PingMessage::to_message() const { - return sentry::common::Message{kId, rlp_encode()}; +sentry::Message PingMessage::to_message() const { + return sentry::Message{kId, rlp_encode()}; } -sentry::common::Message PongMessage::to_message() const { - return sentry::common::Message{kId, rlp_encode()}; +sentry::Message PongMessage::to_message() const { + return sentry::Message{kId, rlp_encode()}; } } // namespace silkworm::sentry::rlpx diff --git a/silkworm/sentry/rlpx/ping_message.hpp b/silkworm/sentry/rlpx/ping_message.hpp index 68d07d9548..6b00cdf674 100644 --- a/silkworm/sentry/rlpx/ping_message.hpp +++ b/silkworm/sentry/rlpx/ping_message.hpp @@ -23,13 +23,13 @@ namespace silkworm::sentry::rlpx { struct PingMessage { [[nodiscard]] Bytes rlp_encode() const; - [[nodiscard]] sentry::common::Message to_message() const; + [[nodiscard]] sentry::Message to_message() const; static const uint8_t kId; }; struct PongMessage { [[nodiscard]] Bytes rlp_encode() const; - [[nodiscard]] sentry::common::Message to_message() const; + [[nodiscard]] sentry::Message to_message() const; static const uint8_t kId; }; diff --git a/silkworm/sentry/rlpx/protocol.hpp b/silkworm/sentry/rlpx/protocol.hpp index b188afc5f6..22d1a36bbc 100644 --- a/silkworm/sentry/rlpx/protocol.hpp +++ b/silkworm/sentry/rlpx/protocol.hpp @@ -28,8 +28,8 @@ namespace silkworm::sentry::rlpx { struct Protocol { virtual ~Protocol() = default; [[nodiscard]] virtual std::pair capability() = 0; - [[nodiscard]] virtual common::Message first_message() = 0; - virtual void handle_peer_first_message(const common::Message& message) = 0; + [[nodiscard]] virtual Message first_message() = 0; + virtual void handle_peer_first_message(const Message& message) = 0; class IncompatiblePeerError : public std::runtime_error { public: diff --git a/silkworm/sentry/rlpx/server.cpp b/silkworm/sentry/rlpx/server.cpp index 09a397ccae..e879b8eec7 100644 --- a/silkworm/sentry/rlpx/server.cpp +++ b/silkworm/sentry/rlpx/server.cpp @@ -41,7 +41,7 @@ ip::tcp::endpoint Server::listen_endpoint() const { Task Server::start( silkworm::rpc::ServerContextPool& context_pool, - common::EccKeyPair node_key, + EccKeyPair node_key, std::string client_id, std::function()> protocol_factory) { auto executor = co_await this_coro::executor; @@ -62,12 +62,12 @@ Task Server::start( acceptor.bind(endpoint); acceptor.listen(); - common::EnodeUrl node_url{node_key.public_key(), endpoint.address(), port_}; + EnodeUrl node_url{node_key.public_key(), endpoint.address(), port_}; log::Info("sentry") << "rlpx::Server is listening at " << node_url.to_string(); while (acceptor.is_open()) { auto& client_context = context_pool.next_io_context(); - common::SocketStream stream{client_context}; + SocketStream stream{client_context}; co_await acceptor.async_accept(stream.socket(), use_awaitable); auto remote_endpoint = stream.socket().remote_endpoint(); diff --git a/silkworm/sentry/rlpx/server.hpp b/silkworm/sentry/rlpx/server.hpp index ed4d08bc56..97d78bfce8 100644 --- a/silkworm/sentry/rlpx/server.hpp +++ b/silkworm/sentry/rlpx/server.hpp @@ -43,7 +43,7 @@ class Server final { Task start( silkworm::rpc::ServerContextPool& context_pool, - common::EccKeyPair node_key, + EccKeyPair node_key, std::string client_id, std::function()> protocol_factory); diff --git a/silkworm/sentry/sentry.cpp b/silkworm/sentry/sentry.cpp index 21558baf6a..f67a376e31 100644 --- a/silkworm/sentry/sentry.cpp +++ b/silkworm/sentry/sentry.cpp @@ -30,8 +30,8 @@ #include #include -#include "api/api_common/node_info.hpp" -#include "api/api_common/service.hpp" +#include "api/common/node_info.hpp" +#include "api/common/service.hpp" #include "api/router/direct_service.hpp" #include "api/router/service_router.hpp" #include "discovery/discovery.hpp" @@ -61,7 +61,7 @@ class SentryImpl final { Task run(); - [[nodiscard]] std::shared_ptr service() { return direct_service_; } + [[nodiscard]] std::shared_ptr service() { return direct_service_; } private: void setup_node_key(); @@ -79,10 +79,10 @@ class SentryImpl final { std::unique_ptr make_client(); std::function()> client_factory(); [[nodiscard]] std::string client_id() const; - [[nodiscard]] common::EnodeUrl make_node_url() const; - [[nodiscard]] api::api_common::NodeInfo make_node_info() const; - [[nodiscard]] std::function node_info_provider() const; - [[nodiscard]] std::function node_key_provider() const; + [[nodiscard]] EnodeUrl make_node_url() const; + [[nodiscard]] api::NodeInfo make_node_info() const; + [[nodiscard]] std::function node_info_provider() const; + [[nodiscard]] std::function node_key_provider() const; Settings settings_; std::optional node_key_; @@ -117,7 +117,7 @@ static api::router::ServiceRouter make_service_router( MessageSender& message_sender, MessageReceiver& message_receiver, PeerManagerApi& peer_manager_api, - std::function node_info_provider) { + std::function node_info_provider) { return api::router::ServiceRouter{ eth::Protocol::kVersion, status_channel, @@ -244,17 +244,17 @@ std::string SentryImpl::client_id() const { return "silkworm"; } -common::EnodeUrl SentryImpl::make_node_url() const { +EnodeUrl SentryImpl::make_node_url() const { assert(node_key_); assert(public_ip_); - return common::EnodeUrl{ + return EnodeUrl{ node_key_.value().public_key(), public_ip_.value(), settings_.port, }; } -api::api_common::NodeInfo SentryImpl::make_node_info() const { +api::NodeInfo SentryImpl::make_node_info() const { return { make_node_url(), client_id(), @@ -263,11 +263,11 @@ api::api_common::NodeInfo SentryImpl::make_node_info() const { }; } -std::function SentryImpl::node_info_provider() const { +std::function SentryImpl::node_info_provider() const { return [this] { return this->make_node_info(); }; } -std::function SentryImpl::node_key_provider() const { +std::function SentryImpl::node_key_provider() const { return [this] { assert(this->node_key_); return this->node_key_.value(); @@ -286,7 +286,7 @@ Task Sentry::run() { return p_impl_->run(); } -Task> Sentry::service() { +Task> Sentry::service() { co_return p_impl_->service(); } diff --git a/silkworm/sentry/sentry.hpp b/silkworm/sentry/sentry.hpp index 5faf9d74e3..48f479159f 100644 --- a/silkworm/sentry/sentry.hpp +++ b/silkworm/sentry/sentry.hpp @@ -22,14 +22,14 @@ #include -#include "api/api_common/sentry_client.hpp" +#include "api/common/sentry_client.hpp" #include "settings.hpp" namespace silkworm::sentry { class SentryImpl; -class Sentry final : public api::api_common::SentryClient { +class Sentry final : public api::SentryClient { public: explicit Sentry(Settings settings, silkworm::rpc::ServerContextPool& context_pool); ~Sentry() override; @@ -39,7 +39,7 @@ class Sentry final : public api::api_common::SentryClient { Task run(); - Task> service() override; + Task> service() override; [[nodiscard]] bool is_ready() override; void on_disconnect(std::function()> callback) override; Task reconnect() override; diff --git a/silkworm/sentry/session_sentry_client.cpp b/silkworm/sentry/session_sentry_client.cpp index 4919a93841..e0c825677b 100644 --- a/silkworm/sentry/session_sentry_client.cpp +++ b/silkworm/sentry/session_sentry_client.cpp @@ -27,7 +27,7 @@ namespace silkworm::sentry { using namespace boost::asio; -class SessionSentryClientImpl : public api::api_common::SentryClient { +class SessionSentryClientImpl : public api::SentryClient { private: enum class State { kInit, @@ -48,7 +48,7 @@ class SessionSentryClientImpl : public api::api_common::SentryClient { using Waiter = concurrency::AwaitableConditionVariable::Waiter; SessionSentryClientImpl( - std::shared_ptr sentry_client, + std::shared_ptr sentry_client, StatusDataProvider status_data_provider) : sentry_client_(std::move(sentry_client)), status_data_provider_(std::move(status_data_provider)), @@ -61,7 +61,7 @@ class SessionSentryClientImpl : public api::api_common::SentryClient { sentry_client_->on_disconnect([]() -> Task { co_return; }); } - Task> service() override { + Task> service() override { co_await run_transitions_until_ready(Event::kSessionRequired); co_return (co_await sentry_client_->service()); } @@ -128,7 +128,7 @@ class SessionSentryClientImpl : public api::api_common::SentryClient { // Delay reconnection to make these corner cases less likely: // - a late failed call triggers Event::kDisconnected again, and we'll have to redo the handshake; // - a successful reconnect right after co_await service() where a call would proceed without a handshake; - co_await common::sleep(1s); + co_await sleep(1s); co_await sentry_client_->reconnect(); break; } @@ -170,7 +170,7 @@ class SessionSentryClientImpl : public api::api_common::SentryClient { return run_transitions_until_ready(Event::kDisconnected); } - std::shared_ptr sentry_client_; + std::shared_ptr sentry_client_; StatusDataProvider status_data_provider_; uint8_t eth_version_; State state_; @@ -179,7 +179,7 @@ class SessionSentryClientImpl : public api::api_common::SentryClient { }; SessionSentryClient::SessionSentryClient( - std::shared_ptr sentry_client, + std::shared_ptr sentry_client, StatusDataProvider status_data_provider) : p_impl_(std::make_unique(sentry_client, status_data_provider)) { } @@ -188,7 +188,7 @@ SessionSentryClient::~SessionSentryClient() { [[maybe_unused]] int non_trivial_destructor; // silent clang-tidy } -Task> SessionSentryClient::service() { +Task> SessionSentryClient::service() { return p_impl_->service(); } diff --git a/silkworm/sentry/session_sentry_client.hpp b/silkworm/sentry/session_sentry_client.hpp index d08eacd428..0c6e611518 100644 --- a/silkworm/sentry/session_sentry_client.hpp +++ b/silkworm/sentry/session_sentry_client.hpp @@ -21,23 +21,23 @@ #include -#include +#include #include namespace silkworm::sentry { class SessionSentryClientImpl; -class SessionSentryClient : public api::api_common::SentryClient { +class SessionSentryClient : public api::SentryClient { public: using StatusDataProvider = std::function(uint8_t eth_version)>; SessionSentryClient( - std::shared_ptr sentry_client, + std::shared_ptr sentry_client, StatusDataProvider status_data_provider); ~SessionSentryClient() override; - Task> service() override; + Task> service() override; [[nodiscard]] bool is_ready() override; void on_disconnect(std::function()> callback) override; diff --git a/silkworm/sentry/settings.hpp b/silkworm/sentry/settings.hpp index 713856b1de..c4af853d85 100644 --- a/silkworm/sentry/settings.hpp +++ b/silkworm/sentry/settings.hpp @@ -51,7 +51,7 @@ struct Settings { std::optional> node_key; - std::vector static_peers; + std::vector static_peers; bool no_discover{true}; diff --git a/silkworm/sentry/status_manager.hpp b/silkworm/sentry/status_manager.hpp index 4c8c73a487..bd70f0203a 100644 --- a/silkworm/sentry/status_manager.hpp +++ b/silkworm/sentry/status_manager.hpp @@ -47,7 +47,7 @@ class StatusManager { private: concurrency::Channel status_channel_; - common::AtomicValue status_; + AtomicValue status_; }; } // namespace silkworm::sentry diff --git a/silkworm/sync/block_exchange.cpp b/silkworm/sync/block_exchange.cpp index f6cef36714..a618b0606a 100644 --- a/silkworm/sync/block_exchange.cpp +++ b/silkworm/sync/block_exchange.cpp @@ -31,7 +31,7 @@ namespace silkworm { -using silkworm::sentry::api::api_common::MessageFromPeer; +using silkworm::sentry::api::MessageFromPeer; BlockExchange::BlockExchange(SentryClient& sentry, const db::ROAccess& dba, const ChainConfig& chain_config) : db_access_{dba}, diff --git a/silkworm/sync/block_exchange.hpp b/silkworm/sync/block_exchange.hpp index 1c49ce54df..920b34aa99 100644 --- a/silkworm/sync/block_exchange.hpp +++ b/silkworm/sync/block_exchange.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/silkworm/sync/sentry_client.cpp b/silkworm/sync/sentry_client.cpp index 4cc23330a2..1e39857cf4 100644 --- a/silkworm/sync/sentry_client.cpp +++ b/silkworm/sync/sentry_client.cpp @@ -40,13 +40,13 @@ using namespace boost::asio; SentryClient::SentryClient( boost::asio::io_context& io_context, - std::shared_ptr sentry_client) + std::shared_ptr sentry_client) : io_context_{io_context}, sentry_client_{std::move(sentry_client)}, tasks_{io_context, 1000} { } -static std::unique_ptr decode_inbound_message(const silkworm::sentry::api::api_common::MessageFromPeer& message_from_peer) { +static std::unique_ptr decode_inbound_message(const silkworm::sentry::api::MessageFromPeer& message_from_peer) { using sentry::eth::MessageId; auto eth_message_id = sentry::eth::eth_message_id_from_common_id(message_from_peer.message.id); PeerId peer_id = message_from_peer.peer_public_key->serialized(); @@ -71,7 +71,7 @@ static std::unique_ptr decode_inbound_message(const silkworm::se static constexpr std::string_view kLogTitle{"sync::SentryClient"}; -boost::asio::awaitable SentryClient::publish(const silkworm::sentry::api::api_common::MessageFromPeer& message_from_peer) { +boost::asio::awaitable SentryClient::publish(const silkworm::sentry::api::MessageFromPeer& message_from_peer) { using sentry::eth::MessageId; auto eth_message_id = sentry::eth::eth_message_id_from_common_id(message_from_peer.message.id); @@ -117,9 +117,9 @@ boost::asio::awaitable SentryClient::publish(const silkworm::sentry::api:: } } -static silkworm::sentry::api::api_common::MessageIdSet make_message_id_filter() { +static silkworm::sentry::api::MessageIdSet make_message_id_filter() { using namespace sentry::eth; - silkworm::sentry::api::api_common::MessageIdSet ids = { + silkworm::sentry::api::MessageIdSet ids = { common_message_id_from_eth_id(MessageId::kGetBlockHeaders), common_message_id_from_eth_id(MessageId::kGetBlockBodies), @@ -157,14 +157,14 @@ static T sync_spawn(concurrency::TaskGroup& tasks, io_context& io_context, await return promise.get_future().get(); } -static sentry::common::Message sentry_message_from_outbound_message(const OutboundMessage& outbound_message) { - return sentry::common::Message{ +static sentry::Message sentry_message_from_outbound_message(const OutboundMessage& outbound_message) { + return sentry::Message{ sentry::eth::common_message_id_from_eth_id(outbound_message.eth_message_id()), outbound_message.message_data(), }; } -static SentryClient::PeerIds peer_ids_from_peer_keys(const silkworm::sentry::api::api_common::Service::PeerKeys& peer_keys) { +static SentryClient::PeerIds peer_ids_from_peer_keys(const silkworm::sentry::api::Service::PeerKeys& peer_keys) { SentryClient::PeerIds peer_ids; for (auto& peer_key : peer_keys) { peer_ids.push_back(peer_key.serialized()); @@ -174,7 +174,7 @@ static SentryClient::PeerIds peer_ids_from_peer_keys(const silkworm::sentry::api awaitable SentryClient::send_message_by_id_async(const OutboundMessage& outbound_message, const PeerId& peer_id) { auto message = sentry_message_from_outbound_message(outbound_message); - auto peer_public_key = sentry::common::EccPublicKey::deserialize(peer_id); + auto peer_public_key = sentry::EccPublicKey::deserialize(peer_id); auto service = co_await sentry_client_->service(); auto peer_keys = co_await service->send_message_by_id(std::move(message), std::move(peer_public_key)); co_return peer_ids_from_peer_keys(peer_keys); @@ -218,7 +218,7 @@ SentryClient::PeerIds SentryClient::send_message_by_min_block(const OutboundMess } awaitable SentryClient::peer_min_block_async(const PeerId& peer_id, BlockNum /*min_block*/) { - auto peer_public_key = sentry::common::EccPublicKey::deserialize(peer_id); + auto peer_public_key = sentry::EccPublicKey::deserialize(peer_id); auto service = co_await sentry_client_->service(); co_await service->peer_min_block(std::move(peer_public_key)); } @@ -234,7 +234,7 @@ boost::asio::awaitable SentryClient::async_run() { } boost::asio::awaitable SentryClient::receive_messages() { - std::function(silkworm::sentry::api::api_common::MessageFromPeer)> consumer = [this](auto message_from_peer) -> awaitable { + std::function(silkworm::sentry::api::MessageFromPeer)> consumer = [this](auto message_from_peer) -> awaitable { co_await this->publish(message_from_peer); }; @@ -242,7 +242,7 @@ boost::asio::awaitable SentryClient::receive_messages() { co_await service->messages(make_message_id_filter(), std::move(consumer)); } -static std::string describe_peer_info(const std::optional& peer_info_opt) { +static std::string describe_peer_info(const std::optional& peer_info_opt) { if (!peer_info_opt) { return "-info-not-found-"; } else { @@ -253,14 +253,14 @@ static std::string describe_peer_info(const std::optional& peer_info_opt, + const silkworm::sentry::api::PeerEvent& event, + const std::optional& peer_info_opt, uint64_t active_peers) { PeerId peer_id = event.peer_public_key->serialized(); std::string info = describe_peer_info(peer_info_opt); std::string event_desc; - if (event.event_id == silkworm::sentry::api::api_common::PeerEventId::kAdded) { + if (event.event_id == silkworm::sentry::api::PeerEventId::kAdded) { event_desc = "connected"; } else { event_desc = "disconnected"; @@ -279,7 +279,7 @@ boost::asio::awaitable SentryClient::receive_peer_events() { // This initial value is later updated by on_peer_event. log::Info(kLogTitle) << (co_await count_active_peers_async()) << " active peers"; - std::function(silkworm::sentry::api::api_common::PeerEvent)> consumer = [this](auto event) -> awaitable { + std::function(silkworm::sentry::api::PeerEvent)> consumer = [this](auto event) -> awaitable { co_await count_active_peers_async(); auto service = co_await sentry_client_->service(); @@ -304,7 +304,7 @@ uint64_t SentryClient::count_active_peers() { } boost::asio::awaitable SentryClient::request_peer_info_async(PeerId peer_id) { - auto peer_public_key = sentry::common::EccPublicKey::deserialize(peer_id); + auto peer_public_key = sentry::EccPublicKey::deserialize(peer_id); auto service = co_await sentry_client_->service(); auto peer_info_opt = co_await service->peer_by_id(std::move(peer_public_key)); co_return describe_peer_info(peer_info_opt); @@ -318,7 +318,7 @@ boost::asio::awaitable SentryClient::penalize_peer_async(PeerId peer_id, P if (penalty == Penalty::NoPenalty) { co_return; } - auto peer_public_key = sentry::common::EccPublicKey::deserialize(peer_id); + auto peer_public_key = sentry::EccPublicKey::deserialize(peer_id); auto service = co_await sentry_client_->service(); co_await service->penalize_peer(std::move(peer_public_key)); } diff --git a/silkworm/sync/sentry_client.hpp b/silkworm/sync/sentry_client.hpp index aa12104d0f..df2c7242ec 100644 --- a/silkworm/sync/sentry_client.hpp +++ b/silkworm/sync/sentry_client.hpp @@ -29,9 +29,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -45,7 +45,7 @@ class SentryClient { public: explicit SentryClient( boost::asio::io_context& io_context, - std::shared_ptr sentry_client); + std::shared_ptr sentry_client); SentryClient(const SentryClient&) = delete; SentryClient(SentryClient&&) = delete; @@ -107,10 +107,10 @@ class SentryClient { boost::asio::awaitable receive_peer_events(); // notifying registered subscribers - boost::asio::awaitable publish(const silkworm::sentry::api::api_common::MessageFromPeer& message_from_peer); + boost::asio::awaitable publish(const silkworm::sentry::api::MessageFromPeer& message_from_peer); boost::asio::io_context& io_context_; - std::shared_ptr sentry_client_; + std::shared_ptr sentry_client_; concurrency::TaskGroup tasks_; std::atomic active_peers_{0}; diff --git a/silkworm/sync/sync.cpp b/silkworm/sync/sync.cpp index 99eb48b395..39cea4405d 100644 --- a/silkworm/sync/sync.cpp +++ b/silkworm/sync/sync.cpp @@ -27,7 +27,7 @@ namespace silkworm::chainsync { Sync::Sync(boost::asio::io_context& io_context, mdbx::env_managed& chaindata_env, execution::Client& execution, - const std::shared_ptr& sentry_client, + const std::shared_ptr& sentry_client, const ChainConfig& config, const EngineRpcSettings& rpc_settings) : sync_sentry_client_{io_context, sentry_client}, diff --git a/silkworm/sync/sync.hpp b/silkworm/sync/sync.hpp index 7029aa0d79..225418d32f 100644 --- a/silkworm/sync/sync.hpp +++ b/silkworm/sync/sync.hpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include "block_exchange.hpp" @@ -48,7 +48,7 @@ class Sync { Sync(boost::asio::io_context& io_context, mdbx::env_managed& chaindata_env, execution::Client& execution, - const std::shared_ptr& sentry_client, + const std::shared_ptr& sentry_client, const ChainConfig& config, const EngineRpcSettings& rpc_settings = {});