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

Commit

Permalink
Revert "using namespace std" changes
Browse files Browse the repository at this point in the history
Also update license message in CapabilityHost files
  • Loading branch information
halfalicious committed Mar 20, 2019
1 parent 4fc76ae commit 185938f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 81 deletions.
58 changes: 29 additions & 29 deletions libethereum/EthereumCapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using namespace dev::eth;
char const* const EthereumCapability::c_stateNames[static_cast<int>(SyncState::Size)] = {
"NotSynced", "Idle", "Waiting", "Blocks", "State"};

chrono::milliseconds constexpr EthereumCapability::c_backgroundWorkInterval;
std::chrono::milliseconds constexpr EthereumCapability::c_backgroundWorkInterval;

namespace
{
Expand Down Expand Up @@ -123,7 +123,7 @@ class EthereumPeerObserver: public EthereumPeerObserverFace
}

void onPeerNewHashes(
NodeID const& _peerID, vector<pair<h256, u256>> const& _hashes) override
NodeID const& _peerID, std::vector<std::pair<h256, u256>> const& _hashes) override
{
try
{
Expand Down Expand Up @@ -236,7 +236,7 @@ class EthereumHostData: public EthereumHostDataFace
blockHash = m_chain.numberHash(static_cast<unsigned>(top)); // override start block hash with the hash of the top block we have
}
}
else if (n <= numeric_limits<unsigned>::max())
else if (n <= std::numeric_limits<unsigned>::max())
blockHash = m_chain.numberHash(static_cast<unsigned>(n));
else
blockHash = {};
Expand Down Expand Up @@ -297,7 +297,7 @@ class EthereumHostData: public EthereumHostDataFace

bytes rlp;
unsigned n = 0;
auto numBodiesToSend = min(count, c_maxBlocks);
auto numBodiesToSend = std::min(count, c_maxBlocks);
for (unsigned i = 0; i < numBodiesToSend && rlp.size() < c_maxPayload; ++i)
{
auto h = _blockHashes[i].toHash<h256>();
Expand Down Expand Up @@ -330,7 +330,7 @@ class EthereumHostData: public EthereumHostDataFace

strings data;
size_t payloadSize = 0;
auto numItemsToSend = min(count, c_maxNodes);
auto numItemsToSend = std::min(count, c_maxNodes);
for (unsigned i = 0; i < numItemsToSend && payloadSize < c_maxPayload; ++i)
{
auto h = _dataHashes[i].toHash<h256>();
Expand All @@ -353,7 +353,7 @@ class EthereumHostData: public EthereumHostDataFace

bytes rlp;
unsigned n = 0;
auto numItemsToSend = min(count, c_maxReceipts);
auto numItemsToSend = std::min(count, c_maxReceipts);
for (unsigned i = 0; i < numItemsToSend && rlp.size() < c_maxPayload; ++i)
{
auto h = _blockHashes[i].toHash<h256>();
Expand Down Expand Up @@ -396,11 +396,11 @@ EthereumCapability::EthereumCapability(shared_ptr<p2p::CapabilityHostFace> _host
m_peerObserver.reset(new EthereumPeerObserver(m_sync, m_tq));
m_latestBlockSent = _ch.currentHash();
m_tq.onImport([this](ImportResult _ir, h256 const& _h, h512 const& _nodeId) { onTransactionImported(_ir, _h, _nodeId); });
random_device seed;
m_urng = mt19937_64(seed());
std::random_device seed;
m_urng = std::mt19937_64(seed());
}

chrono::milliseconds EthereumCapability::backgroundWorkInterval() const
std::chrono::milliseconds EthereumCapability::backgroundWorkInterval() const
{
return c_backgroundWorkInterval;
}
Expand Down Expand Up @@ -439,7 +439,7 @@ void EthereumCapability::completeSync()
void EthereumCapability::maintainTransactions()
{
// Send any new transactions.
unordered_map<NodeID, vector<size_t>> peerTransactions;
unordered_map<NodeID, std::vector<size_t>> peerTransactions;
auto ts = m_tq.topTransactions(c_maxSendTransactions);
{
for (size_t i = 0; i < ts.size(); ++i)
Expand Down Expand Up @@ -483,7 +483,7 @@ void EthereumCapability::maintainTransactions()
}

vector<NodeID> EthereumCapability::selectPeers(
function<bool(EthereumPeer const&)> const& _predicate) const
std::function<bool(EthereumPeer const&)> const& _predicate) const
{
vector<NodeID> allowed;
for (auto const& peer : m_peers)
Expand All @@ -494,21 +494,21 @@ vector<NodeID> EthereumCapability::selectPeers(
return allowed;
}

pair<vector<NodeID>, vector<NodeID>> EthereumCapability::randomPartitionPeers(
vector<NodeID> const& _peers, size_t _number) const
std::pair<std::vector<NodeID>, std::vector<NodeID>> EthereumCapability::randomPartitionPeers(
std::vector<NodeID> const& _peers, std::size_t _number) const
{
vector<NodeID> part1(_peers);
vector<NodeID> part2;

if (_number >= _peers.size())
return make_pair(part1, part2);
return std::make_pair(part1, part2);

shuffle(part1.begin(), part1.end(), m_urng);
std::shuffle(part1.begin(), part1.end(), m_urng);

// Remove elements from the end of the shuffled part1 vector and move them to part2.
move(part1.begin() + _number, part1.end(), back_inserter(part2));
std::move(part1.begin() + _number, part1.end(), std::back_inserter(part2));
part1.erase(part1.begin() + _number, part1.end());
return make_pair(move(part1), move(part2));
return std::make_pair(move(part1), move(part2));
}

void EthereumCapability::maintainBlocks(h256 const& _currentHash)
Expand All @@ -531,11 +531,11 @@ void EthereumCapability::maintainBlocks(h256 const& _currentHash)
[&](EthereumPeer const& _peer) { return !_peer.isBlockKnown(_currentHash); });

auto const peersToSendNumber =
max<size_t>(c_minBlockBroadcastPeers, sqrt(m_peers.size()));
std::max<std::size_t>(c_minBlockBroadcastPeers, std::sqrt(m_peers.size()));

vector<NodeID> peersToSend;
vector<NodeID> peersToAnnounce;
tie(peersToSend, peersToAnnounce) =
std::vector<NodeID> peersToSend;
std::vector<NodeID> peersToAnnounce;
std::tie(peersToSend, peersToAnnounce) =
randomPartitionPeers(peersWithoutBlock, peersToSendNumber);

for (NodeID const& peerID : peersToSend)
Expand Down Expand Up @@ -644,7 +644,7 @@ bool EthereumCapability::interpretCapabilityPacket(
NodeID const& _peerID, unsigned _id, RLP const& _r)
{
auto& peer = m_peers[_peerID];
peer.setLastAsk(chrono::system_clock::to_time_t(chrono::system_clock::now()));
peer.setLastAsk(std::chrono::system_clock::to_time_t(chrono::system_clock::now()));

try
{
Expand Down Expand Up @@ -685,7 +685,7 @@ bool EthereumCapability::interpretCapabilityPacket(
static_cast<unsigned>(maxHeaders) :
c_maxHeadersToSend;

if (skip > numeric_limits<unsigned>::max() - 1)
if (skip > std::numeric_limits<unsigned>::max() - 1)
{
cnetdetails << "Requested block skip is too big: " << skip;
break;
Expand Down Expand Up @@ -765,7 +765,7 @@ bool EthereumCapability::interpretCapabilityPacket(

vector<pair<h256, u256>> hashes(itemCount);
for (unsigned i = 0; i < itemCount; ++i)
hashes[i] = make_pair(_r[i][0].toHash<h256>(), _r[i][1].toInt<u256>());
hashes[i] = std::make_pair(_r[i][0].toHash<h256>(), _r[i][1].toInt<u256>());

m_peerObserver->onPeerNewHashes(_peerID, hashes);
break;
Expand Down Expand Up @@ -842,7 +842,7 @@ bool EthereumCapability::interpretCapabilityPacket(
cnetlog << "Peer causing an Exception: "
<< boost::current_exception_diagnostic_information() << " " << _r;
}
catch (exception const& _e)
catch (std::exception const& _e)
{
cnetlog << "Peer causing an exception: " << _e.what() << " " << _r;
}
Expand Down Expand Up @@ -870,13 +870,13 @@ void EthereumCapability::doBackgroundWork()
}
}

time_t now = chrono::system_clock::to_time_t(chrono::system_clock::now());
time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
if (now - m_lastTick >= 1)
{
m_lastTick = now;
for (auto const& peer : m_peers)
{
time_t now = chrono::system_clock::to_time_t(chrono::system_clock::now());
time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

if (now - peer.second.lastAsk() > c_peerTimeoutSeconds && peer.second.isConversing())
// timeout
Expand All @@ -899,7 +899,7 @@ void EthereumCapability::setAsking(NodeID const& _peerID, Asking _a)
auto& peerStatus = itPeerStatus->second;

peerStatus.setAsking(_a);
peerStatus.setLastAsk(chrono::system_clock::to_time_t(chrono::system_clock::now()));
peerStatus.setLastAsk(std::chrono::system_clock::to_time_t(chrono::system_clock::now()));

m_host->addNote(_peerID, "ask", ::toString(_a));
m_host->addNote(_peerID, "sync",
Expand Down Expand Up @@ -928,7 +928,7 @@ bool EthereumCapability::needsSyncing(NodeID const& _peerID) const
return (peerStatus != m_peers.end() && peerStatus->second.latestHash());
}

void EthereumCapability::disablePeer(NodeID const& _peerID, string const& _problem)
void EthereumCapability::disablePeer(NodeID const& _peerID, std::string const& _problem)
{
m_host->disableCapability(_peerID, name(), _problem);
}
Expand Down
32 changes: 15 additions & 17 deletions libethereum/WarpCapability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <boost/fiber/all.hpp>
#include <chrono>

using namespace std;

namespace dev
{
namespace eth
Expand Down Expand Up @@ -286,22 +284,22 @@ class WarpPeerObserver : public WarpPeerObserverFace
unsigned const m_daoForkBlock;
boost::fibers::promise<bytes> m_manifest;
h256 m_syncingSnapshotHash;
deque<h256> m_neededChunks;
std::deque<h256> m_neededChunks;
boost::fibers::buffered_channel<NodeID> m_freePeers;
boost::filesystem::path const m_snapshotDir;
map<NodeID, boost::fibers::promise<bytes>> m_manifests;
map<NodeID, boost::fibers::promise<bytes>> m_daoForkHeaders;
map<NodeID, h256> m_requestedChunks;
std::map<NodeID, boost::fibers::promise<bytes>> m_manifests;
std::map<NodeID, boost::fibers::promise<bytes>> m_daoForkHeaders;
std::map<NodeID, h256> m_requestedChunks;

unique_ptr<boost::fibers::fiber> m_downloadFiber;
std::unique_ptr<boost::fibers::fiber> m_downloadFiber;

Logger m_logger{createLogger(VerbosityInfo, "snap")};
};

} // namespace


WarpCapability::WarpCapability(shared_ptr<p2p::CapabilityHostFace> _host,
WarpCapability::WarpCapability(std::shared_ptr<p2p::CapabilityHostFace> _host,
BlockChain const& _blockChain, u256 const& _networkId,
boost::filesystem::path const& _snapshotDownloadPath,
std::shared_ptr<SnapshotStorageFace> _snapshotStorage)
Expand All @@ -315,15 +313,15 @@ WarpCapability::WarpCapability(shared_ptr<p2p::CapabilityHostFace> _host,
{
}

chrono::milliseconds WarpCapability::backgroundWorkInterval() const
std::chrono::milliseconds WarpCapability::backgroundWorkInterval() const
{
return c_backgroundWorkInterval;
}

shared_ptr<WarpPeerObserverFace> WarpCapability::createPeerObserver(
std::shared_ptr<WarpPeerObserverFace> WarpCapability::createPeerObserver(
boost::filesystem::path const& _snapshotDownloadPath)
{
return make_shared<WarpPeerObserver>(*this, m_blockChain, _snapshotDownloadPath);
return std::make_shared<WarpPeerObserver>(*this, m_blockChain, _snapshotDownloadPath);
}

void WarpCapability::onConnect(NodeID const& _peerID, u256 const& /* _peerCapabilityVersion */)
Expand All @@ -350,7 +348,7 @@ void WarpCapability::onConnect(NodeID const& _peerID, u256 const& /* _peerCapabi
bool WarpCapability::interpretCapabilityPacket(NodeID const& _peerID, unsigned _id, RLP const& _r)
{
auto& peerStatus = m_peers[_peerID];
peerStatus.m_lastAsk = chrono::system_clock::to_time_t(chrono::system_clock::now());
peerStatus.m_lastAsk = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());

try
{
Expand Down Expand Up @@ -442,7 +440,7 @@ bool WarpCapability::interpretCapabilityPacket(NodeID const& _peerID, unsigned _
cnetlog << "Warp Peer causing an Exception: "
<< boost::current_exception_diagnostic_information() << " " << _r;
}
catch (exception const& _e)
catch (std::exception const& _e)
{
cnetlog << "Warp Peer causing an exception: " << _e.what() << " " << _r;
}
Expand All @@ -460,7 +458,7 @@ void WarpCapability::doBackgroundWork()
{
for (auto const& peer : m_peers)
{
time_t now = chrono::system_clock::to_time_t(chrono::system_clock::now());
time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
auto const& status = peer.second;
if (now - status.m_lastAsk > 10 && status.m_asking != Asking::Nothing)
{
Expand Down Expand Up @@ -534,12 +532,12 @@ void WarpCapability::setAsking(NodeID const& _peerID, Asking _a)
auto& peerStatus = itPeerStatus->second;

peerStatus.m_asking = _a;
peerStatus.m_lastAsk = chrono::system_clock::to_time_t(chrono::system_clock::now());
peerStatus.m_lastAsk = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
}

/// Validates whether peer is able to communicate with the host, disables peer if not
bool WarpCapability::validateStatus(NodeID const& _peerID, h256 const& _genesisHash,
vector<unsigned> const& _protocolVersions, u256 const& _networkId)
std::vector<unsigned> const& _protocolVersions, u256 const& _networkId)
{
auto itPeerStatus = m_peers.find(_peerID);
if (itPeerStatus == m_peers.end())
Expand Down Expand Up @@ -572,7 +570,7 @@ bool WarpCapability::validateStatus(NodeID const& _peerID, h256 const& _genesisH
return true;
}

void WarpCapability::disablePeer(NodeID const& _peerID, string const& _problem)
void WarpCapability::disablePeer(NodeID const& _peerID, std::string const& _problem)
{
m_host->disableCapability(_peerID, name(), _problem);
}
Expand Down
23 changes: 4 additions & 19 deletions libp2p/CapabilityHost.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
/*
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 "CapabilityHost.h"
#include "Host.h"
#include "Session.h"

using namespace std;

namespace dev
{
namespace p2p
Expand Down Expand Up @@ -111,7 +96,7 @@ class CapabilityHost : public CapabilityHostFace
m_host.forEachPeer(_capabilityName, _f);
}

void postWork(function<void()> _f) override { m_host.postWork(move(_f)); }
void postWork(std::function<void()> _f) override { m_host.postWork(move(_f)); }

private:
Host& m_host;
Expand Down
19 changes: 3 additions & 16 deletions libp2p/CapabilityHost.h
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.

#pragma once

Expand Down

0 comments on commit 185938f

Please sign in to comment.