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

Commit 2d2d072

Browse files
committed
Address PR feedback
Move logging to separate host function, add "looking for peers" message, and use Host helpers to retrieve peer count and peer session info vector. Also rename Host::peerSessionInfo to Host::peerSessionInfos so it more accurately reflects what the function is returning (vector of peerSessionInfo) Also use const& when iterating over capabilities and update changelog so that new "changed" entry is grouped with other "changed" entries.
1 parent 4596b2b commit 2d2d072

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
- Added: [#5537](https://github.com/ethereum/aleth/pull/5537) Creating Ethereum Node Record (ENR) at program start.
66
- Added: [#5557](https://github.com/ethereum/aleth/pull/5557) Improved debug logging of full sync.
77
- Added: [#5564](https://github.com/ethereum/aleth/pull/5564) Improved help output of Aleth by adding list of channels.
8+
- Added: [#5575](https://github.com/ethereum/aleth/pull/5575) Log active peer count and peer list every 30 seconds.
89
- Changed: [#5559](https://github.com/ethereum/aleth/pull/5559) Update peer validation error messages.
910
- Fixed: [#5562](https://github.com/ethereum/aleth/pull/5562) Don't send header request messages to peers that haven't sent us Status yet.
1011
- Changed: [#5568](https://github.com/ethereum/aleth/pull/5568) Improve rlpx handshake log messages and create new rlpx log channel.
11-
- Added: [#5575](https://github.com/ethereum/aleth/pull/5575) Log active peer count and peer list every 30 seconds.
1212

1313
## [1.6.0] - 2019-04-16
1414

libp2p/Common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ inline boost::log::formatting_ostream& operator<<(
272272
{
273273
_strm << _peerSessionInfo.id << "|" << _peerSessionInfo.clientVersion << "|"
274274
<< _peerSessionInfo.host << "|" << _peerSessionInfo.port << "|";
275-
for (auto cap : _peerSessionInfo.caps)
275+
for (auto const& cap : _peerSessionInfo.caps)
276276
_strm << "(" << cap.first << "," << cap.second << ")";
277277
return _strm;
278278
}

libp2p/Host.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ void Host::connect(shared_ptr<Peer> const& _p)
687687
});
688688
}
689689

690-
PeerSessionInfos Host::peerSessionInfo() const
690+
PeerSessionInfos Host::peerSessionInfos() const
691691
{
692692
if (!m_run)
693693
return PeerSessionInfos();
@@ -726,6 +726,7 @@ void Host::run(boost::system::error_code const& _ec)
726726
m_connecting.remove_if([](weak_ptr<RLPXHandshake> h){ return h.expired(); });
727727

728728
keepAlivePeers();
729+
logActivePeers();
729730

730731
// At this time peers will be disconnected based on natural TCP timeout.
731732
// disconnectLatePeers needs to be updated for the assumption that Session
@@ -844,36 +845,34 @@ void Host::keepAlivePeers()
844845
if (!m_run || chrono::steady_clock::now() - c_keepAliveInterval < m_lastPing)
845846
return;
846847

847-
bool logActivePeers =
848-
chrono::steady_clock::now() - c_logActivePeersInterval > m_lastPeerLogMessage;
849-
std::vector<PeerSessionInfo> peerSessionInfos;
850848
RecursiveGuard l(x_sessions);
851849
{
852850
for (auto it = m_sessions.begin(); it != m_sessions.end();)
853851
if (auto p = it->second.lock())
854852
{
855853
p->ping();
856854
++it;
857-
if (logActivePeers)
858-
peerSessionInfos.push_back(p->info());
859855
}
860856
else
861857
it = m_sessions.erase(it);
862858
}
863859

864-
if (logActivePeers)
865-
{
866-
LOG(m_logger) << "Active peers: " << peerSessionInfos.size();
867-
for (auto const& peerInfo : peerSessionInfos)
868-
{
869-
LOG(m_detailsLogger) << "Peer: " << peerInfo;
870-
}
871-
m_lastPeerLogMessage = chrono::steady_clock::now();
872-
}
873-
874860
m_lastPing = chrono::steady_clock::now();
875861
}
876862

863+
void Host::logActivePeers()
864+
{
865+
if (!m_run || chrono::steady_clock::now() - c_logActivePeersInterval < m_lastPeerLogMessage)
866+
return;
867+
868+
LOG(m_infoLogger) << "Active peer count: " << peerCount();
869+
if (m_netConfig.discovery)
870+
LOG(m_infoLogger) << "Looking for peers...";
871+
872+
LOG(m_detailsLogger) << peerSessionInfos();
873+
m_lastPeerLogMessage = chrono::steady_clock::now();
874+
}
875+
877876
void Host::disconnectLatePeers()
878877
{
879878
auto now = chrono::steady_clock::now();

libp2p/Host.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Host: public Worker
168168
void setPeerStretch(unsigned _n) { m_stretchPeers = _n; }
169169

170170
/// Get peer information.
171-
PeerSessionInfos peerSessionInfo() const;
171+
PeerSessionInfos peerSessionInfos() const;
172172

173173
/// Get number of peers connected.
174174
size_t peerCount() const;
@@ -270,6 +270,9 @@ class Host: public Worker
270270
/// Ping the peers to update the latency information and disconnect peers which have timed out.
271271
void keepAlivePeers();
272272

273+
/// Log count of active peers and information about each peer
274+
void logActivePeers();
275+
273276
/// Disconnect peers which didn't respond to keepAlivePeers ping prior to c_keepAliveTimeOut.
274277
void disconnectLatePeers();
275278

@@ -377,6 +380,7 @@ class Host: public Worker
377380

378381
Logger m_logger{createLogger(VerbosityDebug, "net")};
379382
Logger m_detailsLogger{createLogger(VerbosityTrace, "net")};
383+
Logger m_infoLogger{createLogger(VerbosityInfo, "net")};
380384
};
381385

382386
}

libwebthree/WebThree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ std::string WebThreeDirect::composeClientVersion(std::string const& _client)
8080

8181
std::vector<PeerSessionInfo> WebThreeDirect::peers()
8282
{
83-
return m_net.peerSessionInfo();
83+
return m_net.peerSessionInfos();
8484
}
8585

8686
size_t WebThreeDirect::peerCount() const

test/unittests/libp2p/peer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ BOOST_AUTO_TEST_CASE(requirePeer)
274274
BOOST_REQUIRE_EQUAL(host1peerCount, 1);
275275
BOOST_REQUIRE_EQUAL(host2peerCount, 1);
276276

277-
PeerSessionInfos sis1 = host1.peerSessionInfo();
278-
PeerSessionInfos sis2 = host2.peerSessionInfo();
277+
PeerSessionInfos sis1 = host1.peerSessionInfos();
278+
PeerSessionInfos sis2 = host2.peerSessionInfos();
279279

280280
BOOST_REQUIRE_EQUAL(sis1.size(), 1);
281281
BOOST_REQUIRE_EQUAL(sis2.size(), 1);

0 commit comments

Comments
 (0)