1515#include < chrono>
1616#include < thread>
1717
18- using namespace std ;
1918using namespace dev ;
2019using namespace dev ::eth;
2120
2221char const * const EthereumCapability::c_stateNames[static_cast <int >(SyncState::Size)] = {
2322 " NotSynced" , " Idle" , " Waiting" , " Blocks" , " State" };
2423
25- chrono::milliseconds constexpr EthereumCapability::c_backgroundWorkInterval;
24+ std:: chrono::milliseconds constexpr EthereumCapability::c_backgroundWorkInterval;
2625
2726namespace
2827{
@@ -32,7 +31,7 @@ constexpr unsigned c_maxIncomingNewHashes = 1024;
3231constexpr unsigned c_peerTimeoutSeconds = 10 ;
3332constexpr int c_minBlockBroadcastPeers = 4 ;
3433
35- string toString (Asking _a)
34+ std:: string toString (Asking _a)
3635{
3736 switch (_a)
3837 {
@@ -59,7 +58,7 @@ string toString(Asking _a)
5958class EthereumPeerObserver : public EthereumPeerObserverFace
6059{
6160public:
62- EthereumPeerObserver (shared_ptr<BlockChainSync> _sync, TransactionQueue& _tq): m_sync(_sync), m_tq(_tq) {}
61+ EthereumPeerObserver (std:: shared_ptr<BlockChainSync> _sync, TransactionQueue& _tq): m_sync(_sync), m_tq(_tq) {}
6362
6463 void onPeerStatus (EthereumPeer const & _peer) override
6564 {
@@ -78,7 +77,7 @@ class EthereumPeerObserver: public EthereumPeerObserverFace
7877 void onPeerTransactions (NodeID const & _peerID, RLP const & _r) override
7978 {
8079 unsigned itemCount = _r.itemCount ();
81- LOG (m_logger) << " Transactions (" << dec << itemCount << " entries)" ;
80+ LOG (m_logger) << " Transactions (" << std:: dec << itemCount << " entries)" ;
8281 m_tq.enqueue (_r, _peerID);
8382 }
8483
@@ -123,7 +122,7 @@ class EthereumPeerObserver: public EthereumPeerObserverFace
123122 }
124123
125124 void onPeerNewHashes (
126- NodeID const & _peerID, vector<pair<h256, u256>> const & _hashes) override
125+ NodeID const & _peerID, std:: vector<std:: pair<h256, u256>> const & _hashes) override
127126 {
128127 try
129128 {
@@ -154,17 +153,17 @@ class EthereumPeerObserver: public EthereumPeerObserverFace
154153 void onPeerNodeData (NodeID const & /* _peerID */ , RLP const & _r) override
155154 {
156155 unsigned itemCount = _r.itemCount ();
157- LOG (m_logger) << " Node Data (" << dec << itemCount << " entries)" ;
156+ LOG (m_logger) << " Node Data (" << std:: dec << itemCount << " entries)" ;
158157 }
159158
160159 void onPeerReceipts (NodeID const & /* _peerID */ , RLP const & _r) override
161160 {
162161 unsigned itemCount = _r.itemCount ();
163- LOG (m_logger) << " Receipts (" << dec << itemCount << " entries)" ;
162+ LOG (m_logger) << " Receipts (" << std:: dec << itemCount << " entries)" ;
164163 }
165164
166165private:
167- shared_ptr<BlockChainSync> m_sync;
166+ std:: shared_ptr<BlockChainSync> m_sync;
168167 TransactionQueue& m_tq;
169168
170169 Logger m_logger{createLogger (VerbosityDebug, " host" )};
@@ -175,7 +174,7 @@ class EthereumHostData: public EthereumHostDataFace
175174public:
176175 EthereumHostData (BlockChain const & _chain, OverlayDB const & _db): m_chain(_chain), m_db(_db) {}
177176
178- pair<bytes, unsigned > blockHeaders (RLP const & _blockId, unsigned _maxHeaders, u256 _skip, bool _reverse) const override
177+ std:: pair<bytes, unsigned > blockHeaders (RLP const & _blockId, unsigned _maxHeaders, u256 _skip, bool _reverse) const override
179178 {
180179 auto numHeadersToSend = _maxHeaders;
181180
@@ -236,7 +235,7 @@ class EthereumHostData: public EthereumHostDataFace
236235 blockHash = m_chain.numberHash (static_cast <unsigned >(top)); // override start block hash with the hash of the top block we have
237236 }
238237 }
239- else if (n <= numeric_limits<unsigned >::max ())
238+ else if (n <= std:: numeric_limits<unsigned >::max ())
240239 blockHash = m_chain.numberHash (static_cast <unsigned >(n));
241240 else
242241 blockHash = {};
@@ -273,7 +272,7 @@ class EthereumHostData: public EthereumHostDataFace
273272
274273 bytes rlp;
275274 unsigned itemCount = 0 ;
276- vector<h256> hashes;
275+ std:: vector<h256> hashes;
277276 for (unsigned i = 0 ; i != numHeadersToSend; ++i)
278277 {
279278 if (!blockHash || !m_chain.isKnown (blockHash))
@@ -288,16 +287,16 @@ class EthereumHostData: public EthereumHostDataFace
288287 for (unsigned i = 0 ; i < hashes.size () && rlp.size () < c_maxPayload; ++i)
289288 rlp += m_chain.headerData (hashes[_reverse ? i : hashes.size () - 1 - i]);
290289
291- return make_pair (rlp, itemCount);
290+ return std:: make_pair (rlp, itemCount);
292291 }
293292
294- pair<bytes, unsigned > blockBodies (RLP const & _blockHashes) const override
293+ std:: pair<bytes, unsigned > blockBodies (RLP const & _blockHashes) const override
295294 {
296295 unsigned const count = static_cast <unsigned >(_blockHashes.itemCount ());
297296
298297 bytes rlp;
299298 unsigned n = 0 ;
300- auto numBodiesToSend = min (count, c_maxBlocks);
299+ auto numBodiesToSend = std:: min (count, c_maxBlocks);
301300 for (unsigned i = 0 ; i < numBodiesToSend && rlp.size () < c_maxPayload; ++i)
302301 {
303302 auto h = _blockHashes[i].toHash <h256>();
@@ -321,7 +320,7 @@ class EthereumHostData: public EthereumHostDataFace
321320 << " blocks unknown; " << (count > c_maxBlocks ? count - c_maxBlocks : 0 )
322321 << " blocks ignored" ;
323322
324- return make_pair (rlp, n);
323+ return std:: make_pair (rlp, n);
325324 }
326325
327326 strings nodeData (RLP const & _dataHashes) const override
@@ -330,7 +329,7 @@ class EthereumHostData: public EthereumHostDataFace
330329
331330 strings data;
332331 size_t payloadSize = 0 ;
333- auto numItemsToSend = min (count, c_maxNodes);
332+ auto numItemsToSend = std:: min (count, c_maxNodes);
334333 for (unsigned i = 0 ; i < numItemsToSend && payloadSize < c_maxPayload; ++i)
335334 {
336335 auto h = _dataHashes[i].toHash <h256>();
@@ -347,13 +346,13 @@ class EthereumHostData: public EthereumHostDataFace
347346 return data;
348347 }
349348
350- pair<bytes, unsigned > receipts (RLP const & _blockHashes) const override
349+ std:: pair<bytes, unsigned > receipts (RLP const & _blockHashes) const override
351350 {
352351 unsigned const count = static_cast <unsigned >(_blockHashes.itemCount ());
353352
354353 bytes rlp;
355354 unsigned n = 0 ;
356- auto numItemsToSend = min (count, c_maxReceipts);
355+ auto numItemsToSend = std:: min (count, c_maxReceipts);
357356 for (unsigned i = 0 ; i < numItemsToSend && rlp.size () < c_maxPayload; ++i)
358357 {
359358 auto h = _blockHashes[i].toHash <h256>();
@@ -369,7 +368,7 @@ class EthereumHostData: public EthereumHostDataFace
369368 << " unknown; " << (count > c_maxReceipts ? count - c_maxReceipts : 0 )
370369 << " ignored" ;
371370
372- return make_pair (rlp, n);
371+ return std:: make_pair (rlp, n);
373372 }
374373
375374private:
@@ -379,7 +378,7 @@ class EthereumHostData: public EthereumHostDataFace
379378
380379}
381380
382- EthereumCapability::EthereumCapability (shared_ptr<p2p::CapabilityHostFace> _host,
381+ EthereumCapability::EthereumCapability (std:: shared_ptr<p2p::CapabilityHostFace> _host,
383382 BlockChain const & _ch, OverlayDB const & _db, TransactionQueue& _tq, BlockQueue& _bq,
384383 u256 _networkId)
385384 : m_host(move(_host)),
@@ -396,11 +395,11 @@ EthereumCapability::EthereumCapability(shared_ptr<p2p::CapabilityHostFace> _host
396395 m_peerObserver.reset (new EthereumPeerObserver (m_sync, m_tq));
397396 m_latestBlockSent = _ch.currentHash ();
398397 m_tq.onImport ([this ](ImportResult _ir, h256 const & _h, h512 const & _nodeId) { onTransactionImported (_ir, _h, _nodeId); });
399- random_device seed;
400- m_urng = mt19937_64 (seed ());
398+ std:: random_device seed;
399+ m_urng = std:: mt19937_64 (seed ());
401400}
402401
403- chrono::milliseconds EthereumCapability::backgroundWorkInterval () const
402+ std:: chrono::milliseconds EthereumCapability::backgroundWorkInterval () const
404403{
405404 return c_backgroundWorkInterval;
406405}
@@ -439,7 +438,7 @@ void EthereumCapability::completeSync()
439438void EthereumCapability::maintainTransactions ()
440439{
441440 // Send any new transactions.
442- unordered_map<NodeID, vector<size_t >> peerTransactions;
441+ std:: unordered_map<NodeID, std:: vector<size_t >> peerTransactions;
443442 auto ts = m_tq.topTransactions (c_maxSendTransactions);
444443 {
445444 for (size_t i = 0 ; i < ts.size (); ++i)
@@ -482,10 +481,10 @@ void EthereumCapability::maintainTransactions()
482481 }
483482}
484483
485- vector<NodeID> EthereumCapability::selectPeers (
486- function<bool (EthereumPeer const &)> const & _predicate) const
484+ std:: vector<NodeID> EthereumCapability::selectPeers (
485+ std:: function<bool (EthereumPeer const &)> const & _predicate) const
487486{
488- vector<NodeID> allowed;
487+ std:: vector<NodeID> allowed;
489488 for (auto const & peer : m_peers)
490489 {
491490 if (_predicate (peer.second ))
@@ -494,21 +493,21 @@ vector<NodeID> EthereumCapability::selectPeers(
494493 return allowed;
495494}
496495
497- pair<vector<NodeID>, vector<NodeID>> EthereumCapability::randomPartitionPeers (
498- vector<NodeID> const & _peers, size_t _number) const
496+ std:: pair<std:: vector<NodeID>, std:: vector<NodeID>> EthereumCapability::randomPartitionPeers (
497+ std:: vector<NodeID> const & _peers, size_t _number) const
499498{
500- vector<NodeID> part1 (_peers);
501- vector<NodeID> part2;
499+ std:: vector<NodeID> part1 (_peers);
500+ std:: vector<NodeID> part2;
502501
503502 if (_number >= _peers.size ())
504- return make_pair (part1, part2);
503+ return std:: make_pair (part1, part2);
505504
506505 shuffle (part1.begin (), part1.end (), m_urng);
507506
508507 // Remove elements from the end of the shuffled part1 vector and move them to part2.
509508 move (part1.begin () + _number, part1.end (), back_inserter (part2));
510509 part1.erase (part1.begin () + _number, part1.end ());
511- return make_pair (move (part1), move (part2));
510+ return std:: make_pair (move (part1), move (part2));
512511}
513512
514513void EthereumCapability::maintainBlocks (h256 const & _currentHash)
@@ -524,17 +523,17 @@ void EthereumCapability::maintainBlocks(h256 const& _currentHash)
524523 LOG (m_logger) << " Sending new blocks (current is " << _currentHash << " , was "
525524 << m_latestBlockSent << " )" ;
526525
527- h256s blocks = get<0 >(m_chain.treeRoute (m_latestBlockSent, _currentHash, false , false , true ));
526+ h256s blocks = std:: get<0 >(m_chain.treeRoute (m_latestBlockSent, _currentHash, false , false , true ));
528527
529528
530529 auto const peersWithoutBlock = selectPeers (
531530 [&](EthereumPeer const & _peer) { return !_peer.isBlockKnown (_currentHash); });
532531
533532 auto const peersToSendNumber =
534- max<size_t >(c_minBlockBroadcastPeers, sqrt (m_peers.size ()));
533+ std:: max<size_t >(c_minBlockBroadcastPeers, sqrt (m_peers.size ()));
535534
536- vector<NodeID> peersToSend;
537- vector<NodeID> peersToAnnounce;
535+ std:: vector<NodeID> peersToSend;
536+ std:: vector<NodeID> peersToAnnounce;
538537 tie (peersToSend, peersToAnnounce) =
539538 randomPartitionPeers (peersWithoutBlock, peersToSendNumber);
540539
@@ -644,7 +643,7 @@ bool EthereumCapability::interpretCapabilityPacket(
644643 NodeID const & _peerID, unsigned _id, RLP const & _r)
645644{
646645 auto & peer = m_peers[_peerID];
647- peer.setLastAsk (chrono::system_clock::to_time_t (chrono::system_clock::now ()));
646+ peer.setLastAsk (std:: chrono::system_clock::to_time_t (std:: chrono::system_clock::now ()));
648647
649648 try
650649 {
@@ -685,13 +684,13 @@ bool EthereumCapability::interpretCapabilityPacket(
685684 static_cast <unsigned >(maxHeaders) :
686685 c_maxHeadersToSend;
687686
688- if (skip > numeric_limits<unsigned >::max () - 1 )
687+ if (skip > std:: numeric_limits<unsigned >::max () - 1 )
689688 {
690689 cnetdetails << " Requested block skip is too big: " << skip;
691690 break ;
692691 }
693692
694- pair<bytes, unsigned > const rlpAndItemCount =
693+ std:: pair<bytes, unsigned > const rlpAndItemCount =
695694 m_hostData->blockHeaders (blockId, numHeadersToSend, skip, reverse);
696695
697696 RLPStream s;
@@ -716,7 +715,7 @@ bool EthereumCapability::interpretCapabilityPacket(
716715 case GetBlockBodiesPacket:
717716 {
718717 unsigned count = static_cast <unsigned >(_r.itemCount ());
719- cnetlog << " GetBlockBodies (" << dec << count << " entries)" ;
718+ cnetlog << " GetBlockBodies (" << std:: dec << count << " entries)" ;
720719
721720 if (!count)
722721 {
@@ -725,7 +724,7 @@ bool EthereumCapability::interpretCapabilityPacket(
725724 break ;
726725 }
727726
728- pair<bytes, unsigned > const rlpAndItemCount = m_hostData->blockBodies (_r);
727+ std:: pair<bytes, unsigned > const rlpAndItemCount = m_hostData->blockBodies (_r);
729728
730729 m_host->updateRating (_peerID, 0 );
731730 RLPStream s;
@@ -754,7 +753,7 @@ bool EthereumCapability::interpretCapabilityPacket(
754753 {
755754 unsigned itemCount = _r.itemCount ();
756755
757- cnetlog << " BlockHashes (" << dec << itemCount << " entries) "
756+ cnetlog << " BlockHashes (" << std:: dec << itemCount << " entries) "
758757 << (itemCount ? " " : " : NoMoreHashes" );
759758
760759 if (itemCount > c_maxIncomingNewHashes)
@@ -763,9 +762,9 @@ bool EthereumCapability::interpretCapabilityPacket(
763762 break ;
764763 }
765764
766- vector<pair<h256, u256>> hashes (itemCount);
765+ std:: vector<std:: pair<h256, u256>> hashes (itemCount);
767766 for (unsigned i = 0 ; i < itemCount; ++i)
768- hashes[i] = make_pair (_r[i][0 ].toHash <h256>(), _r[i][1 ].toInt <u256>());
767+ hashes[i] = std:: make_pair (_r[i][0 ].toHash <h256>(), _r[i][1 ].toInt <u256>());
769768
770769 m_peerObserver->onPeerNewHashes (_peerID, hashes);
771770 break ;
@@ -779,7 +778,7 @@ bool EthereumCapability::interpretCapabilityPacket(
779778 m_host->updateRating (_peerID, -10 );
780779 break ;
781780 }
782- cnetlog << " GetNodeData (" << dec << count << " entries)" ;
781+ cnetlog << " GetNodeData (" << std:: dec << count << " entries)" ;
783782
784783 strings const data = m_hostData->nodeData (_r);
785784
@@ -800,9 +799,9 @@ bool EthereumCapability::interpretCapabilityPacket(
800799 m_host->updateRating (_peerID, -10 );
801800 break ;
802801 }
803- cnetlog << " GetReceipts (" << dec << count << " entries)" ;
802+ cnetlog << " GetReceipts (" << std:: dec << count << " entries)" ;
804803
805- pair<bytes, unsigned > const rlpAndItemCount = m_hostData->receipts (_r);
804+ std:: pair<bytes, unsigned > const rlpAndItemCount = m_hostData->receipts (_r);
806805
807806 m_host->updateRating (_peerID, 0 );
808807 RLPStream s;
@@ -842,7 +841,7 @@ bool EthereumCapability::interpretCapabilityPacket(
842841 cnetlog << " Peer causing an Exception: "
843842 << boost::current_exception_diagnostic_information () << " " << _r;
844843 }
845- catch (exception const & _e)
844+ catch (std:: exception const & _e)
846845 {
847846 cnetlog << " Peer causing an exception: " << _e.what () << " " << _r;
848847 }
@@ -870,13 +869,13 @@ void EthereumCapability::doBackgroundWork()
870869 }
871870 }
872871
873- time_t now = chrono::system_clock::to_time_t (chrono::system_clock::now ());
872+ time_t now = std:: chrono::system_clock::to_time_t (std:: chrono::system_clock::now ());
874873 if (now - m_lastTick >= 1 )
875874 {
876875 m_lastTick = now;
877876 for (auto const & peer : m_peers)
878877 {
879- time_t now = chrono::system_clock::to_time_t (chrono::system_clock::now ());
878+ time_t now = std:: chrono::system_clock::to_time_t (std:: chrono::system_clock::now ());
880879
881880 if (now - peer.second .lastAsk () > c_peerTimeoutSeconds && peer.second .isConversing ())
882881 // timeout
@@ -899,11 +898,11 @@ void EthereumCapability::setAsking(NodeID const& _peerID, Asking _a)
899898 auto & peerStatus = itPeerStatus->second ;
900899
901900 peerStatus.setAsking (_a);
902- peerStatus.setLastAsk (chrono::system_clock::to_time_t (chrono::system_clock::now ()));
901+ peerStatus.setLastAsk (std:: chrono::system_clock::to_time_t (std:: chrono::system_clock::now ()));
903902
904903 m_host->addNote (_peerID, " ask" , ::toString (_a));
905904 m_host->addNote (_peerID, " sync" ,
906- string (isCriticalSyncing (_peerID) ? " ONGOING" : " holding" ) +
905+ std:: string (isCriticalSyncing (_peerID) ? " ONGOING" : " holding" ) +
907906 (needsSyncing (_peerID) ? " & needed" : " " ));
908907}
909908
@@ -928,7 +927,7 @@ bool EthereumCapability::needsSyncing(NodeID const& _peerID) const
928927 return (peerStatus != m_peers.end () && peerStatus->second .latestHash ());
929928}
930929
931- void EthereumCapability::disablePeer (NodeID const & _peerID, string const & _problem)
930+ void EthereumCapability::disablePeer (NodeID const & _peerID, std:: string const & _problem)
932931{
933932 m_host->disableCapability (_peerID, name (), _problem);
934933}
0 commit comments