Browse Source

Add p2p disconnected structured log event

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
643499e491
  1. 2
      libdevcore/StructuredLogger.cpp
  2. 2
      libdevcore/StructuredLogger.h
  3. 2
      libethereum/BlockChain.h
  4. 7
      libp2p/Host.cpp
  5. 2
      libp2p/Session.cpp

2
libdevcore/StructuredLogger.cpp

@ -80,7 +80,7 @@ void StructuredLogger::logP2PConnected(string const& _id, bi::tcp::endpoint cons
} }
} }
void StructuredLogger::logP2PDisconnected(string const& _id, unsigned int _numConnections, bi::tcp::endpoint const& _addr) const void StructuredLogger::logP2PDisconnected(string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections) const
{ {
if (m_enabled) if (m_enabled)
{ {

2
libdevcore/StructuredLogger.h

@ -41,7 +41,7 @@ public:
void logStarting(std::string const& _clientImpl, const char* _ethVersion); void logStarting(std::string const& _clientImpl, const char* _ethVersion);
void logP2PConnected(std::string const& _id, bi::tcp::endpoint const& _addr, void logP2PConnected(std::string const& _id, bi::tcp::endpoint const& _addr,
std::chrono::system_clock::time_point const& _ts, unsigned int _numConnections) const; std::chrono::system_clock::time_point const& _ts, unsigned int _numConnections) const;
void logP2PDisconnected(std::string const& _id, unsigned int _numConnections, bi::tcp::endpoint const& _addr) const; void logP2PDisconnected(std::string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections) const;
void logMinedNewBlock(std::string const& _hash, std::string const& _blockNumber, void logMinedNewBlock(std::string const& _hash, std::string const& _blockNumber,
std::string const& _chainHeadHash, std::string const& _prevHash) const; std::string const& _chainHeadHash, std::string const& _prevHash) const;
void logChainReceivedNewBlock(std::string const& _hash, std::string const& _blockNumber, std::string const& _chainHeadHash, void logChainReceivedNewBlock(std::string const& _hash, std::string const& _blockNumber, std::string const& _chainHeadHash,

2
libethereum/BlockChain.h

@ -97,7 +97,7 @@ public:
BlockInfo info(h256 _hash) const { return BlockInfo(block(_hash)); } BlockInfo info(h256 _hash) const { return BlockInfo(block(_hash)); }
BlockInfo info() const { return BlockInfo(block()); } BlockInfo info() const { return BlockInfo(block()); }
/// Get the familial details concerning a block (or the most recent mined if none given). Thread-safe. /// Get the familiar details concerning a block (or the most recent mined if none given). Thread-safe.
BlockDetails details(h256 _hash) const { return queryExtras<BlockDetails, 0>(_hash, m_details, x_details, NullBlockDetails); } BlockDetails details(h256 _hash) const { return queryExtras<BlockDetails, 0>(_hash, m_details, x_details, NullBlockDetails); }
BlockDetails details() const { return details(currentHash()); } BlockDetails details() const { return details(currentHash()); }

7
libp2p/Host.cpp

@ -159,6 +159,10 @@ void Host::registerPeer(std::shared_ptr<Session> _s, CapDescs const& _caps)
{ {
{ {
clog(NetNote) << "p2p.host.peer.register" << _s->m_peer->id.abridged(); clog(NetNote) << "p2p.host.peer.register" << _s->m_peer->id.abridged();
m_structuredLogger.logP2PConnected(
_s->m_peer->id.abridged(), _s->m_peer->peerEndpoint(),
_s->m_peer->m_lastConnected,
0);// TODO: num_connections
RecursiveGuard l(x_sessions); RecursiveGuard l(x_sessions);
// TODO: temporary loose-coupling; if m_peers already has peer, // TODO: temporary loose-coupling; if m_peers already has peer,
// it is same as _s->m_peer. (fixing next PR) // it is same as _s->m_peer. (fixing next PR)
@ -476,9 +480,6 @@ void Host::connect(std::shared_ptr<Peer> const& _p)
_p->m_lastConnected = std::chrono::system_clock::now(); _p->m_lastConnected = std::chrono::system_clock::now();
_p->m_failedAttempts = 0; _p->m_failedAttempts = 0;
m_structuredLogger.logP2PConnected(_p->id.abridged(), _p->peerEndpoint(), _p->m_lastConnected,
0);// TODO: num_connections
auto ps = make_shared<Session>(this, std::move(*s), _p); auto ps = make_shared<Session>(this, std::move(*s), _p);
ps->start(); ps->start();

2
libp2p/Session.cpp

@ -467,6 +467,8 @@ void Session::drop(DisconnectReason _reason)
void Session::disconnect(DisconnectReason _reason) void Session::disconnect(DisconnectReason _reason)
{ {
clogS(NetConnect) << "Disconnecting (our reason:" << reasonOf(_reason) << ")"; clogS(NetConnect) << "Disconnecting (our reason:" << reasonOf(_reason) << ")";
m_server->m_structuredLogger.logP2PDisconnected(m_info.id.abridged(), m_peer->peerEndpoint(),
0);// TODO: num connections
if (m_socket.is_open()) if (m_socket.is_open())
{ {
RLPStream s; RLPStream s;

Loading…
Cancel
Save