Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Rephrase error messages in EthereumPeer::validate and re-order validation conditions #5559

Merged
merged 4 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,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
[1.7.0]: https://github.com/ethereum/aleth/compare/release/1.6...master
42 changes: 16 additions & 26 deletions libethereum/EthereumPeer.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
// Aleth: Ethereum C++ client, tools and libraries.
// Copyright 2019 Aleth Authors.
// Licensed under the GNU General Public License, Version 3.

#include "EthereumPeer.h"
#include <libethcore/Common.h>
Expand All @@ -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)
Expand Down Expand Up @@ -67,17 +54,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad this doesn't use operator<< overloads for logging, so it outputs long full hash. Maybe change it to outputting .abridged() ?

<< ", 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(
Expand Down