From 2313d1374ccdd0f8027f676511daa315abf98e6a Mon Sep 17 00:00:00 2001 From: Nils-Erik Frantzell Date: Wed, 10 Apr 2019 21:00:56 -0700 Subject: [PATCH 1/4] Reorder peer validation in EthereumPeer::validate Reorder validation so that checks go from the broadest condition (network ID) to the most targeted (unexpected status message) - also rephrase log messages and include host / peer values. The result is that the logs are easier to read and contain more useful information. --- libethereum/EthereumPeer.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index f673e66c854..0e834e31dff 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -67,17 +67,20 @@ void EthereumPeer::setStatus(unsigned _protocolVersion, u256 const& _networkId, std::string EthereumPeer::validate( h256 const& _hostGenesisHash, unsigned _hostProtocolVersion, u256 const& _hostNetworkId) const { - std::string error; - if (m_genesisHash != _hostGenesisHash) - error = "Invalid genesis hash."; + std::stringstream error; + if (m_networkId != _hostNetworkId) + error << "Network identifier mismatch. Host network id: " << _hostNetworkId + << ", peer network id: " << m_networkId; else if (m_protocolVersion != _hostProtocolVersion) - error = "Invalid protocol version."; - else if (m_networkId != _hostNetworkId) - error = "Invalid network identifier."; + error << "Protocol version mismatch. Host protocol version: " << _hostProtocolVersion + << ", peer protocol version: " << m_protocolVersion; + else if (m_genesisHash != _hostGenesisHash) + error << "Genesis hash mismatch. Host genesis hash: " << _hostGenesisHash + << ", peer genesis hash: " << m_genesisHash; else if (m_asking != Asking::State && m_asking != Asking::Nothing) - error = "Peer banned for unexpected status message."; + error << "Peer banned for unexpected status message."; - return error; + return error.str(); } void EthereumPeer::requestStatus( From 13a648eed97e9210ebd98b5fbbcf81ee852ef867 Mon Sep 17 00:00:00 2001 From: Nils-Erik Frantzell Date: Wed, 10 Apr 2019 21:08:29 -0700 Subject: [PATCH 2/4] Update license message Also move static constant to anonymous namespace --- libethereum/EthereumPeer.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index 0e834e31dff..f3738fee042 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -1,19 +1,6 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ +// Aleth: Ethereum C++ client, tools and libraries. +// Copyright 2019 Aleth Authors. +// Licensed under the GNU General Public License, Version 3. #include "EthereumPeer.h" #include @@ -24,10 +11,10 @@ using namespace std; using namespace dev; using namespace dev::eth; -static std::string const c_ethCapability = "eth"; - namespace { +std::string const c_ethCapability = "eth"; + string toString(Asking _a) { switch (_a) From 8f57a2530c5393a6c99fc86352070d070ad3455f Mon Sep 17 00:00:00 2001 From: Nils-Erik Frantzell Date: Wed, 10 Apr 2019 21:18:27 -0700 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e848640298a..d9f5c964613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [1.7.0] - Unreleased - Added: [#5537](https://github.com/ethereum/aleth/pull/5537) Creating Ethereum Node Record (ENR) at program start. +- Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages [1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...master From 649d26d15ef9bde90e89316346801e5713f6b559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 11 Apr 2019 10:49:45 +0200 Subject: [PATCH 4/4] Add missing dot in the CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9f5c964613..f26cd9ea24a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## [1.7.0] - Unreleased - Added: [#5537](https://github.com/ethereum/aleth/pull/5537) Creating Ethereum Node Record (ENR) at program start. -- Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages +- Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages. [1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...master @@ -25,4 +25,4 @@ - Fixed: [#5547](https://github.com/ethereum/aleth/pull/5547) Fix unnecessary slow-down of eth_flush RPC method. [1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...release/1.6 -[1.7.0]: https://github.com/ethereum/aleth/compare/release/1.6...master \ No newline at end of file +[1.7.0]: https://github.com/ethereum/aleth/compare/release/1.6...master