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

Commit 7269bf9

Browse files
committed
Remove redundant error logging from RLPxHandshake
1 parent c73a4ff commit 7269bf9

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

libp2p/RLPxHandshake.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void RLPXHandshake::writeAck()
9797

9898
void RLPXHandshake::writeAckEIP8()
9999
{
100-
LOG(m_logger) << "EIP-8 to";
100+
LOG(m_logger) << "EIP-8 ack to";
101101
RLPStream rlp;
102102
rlp.appendList(3)
103103
<< m_ecdheLocal.pub()
@@ -155,7 +155,7 @@ void RLPXHandshake::readAuth()
155155
void RLPXHandshake::readAuthEIP8()
156156
{
157157
assert(m_authCipher.size() == c_authCipherSizeBytes);
158-
uint16_t size(m_authCipher[0]<<8 | m_authCipher[1]);
158+
uint16_t const size(m_authCipher[0] << 8 | m_authCipher[1]);
159159
LOG(m_logger) << size << " bytes EIP-8 auth from";
160160
m_authCipher.resize((size_t)size + 2);
161161
auto rest = ba::buffer(ba::buffer(m_authCipher) + c_authCipherSizeBytes);
@@ -210,7 +210,7 @@ void RLPXHandshake::readAck()
210210
void RLPXHandshake::readAckEIP8()
211211
{
212212
assert(m_ackCipher.size() == c_ackCipherSizeBytes);
213-
uint16_t size(m_ackCipher[0]<<8 | m_ackCipher[1]);
213+
uint16_t const size(m_ackCipher[0] << 8 | m_ackCipher[1]);
214214
LOG(m_logger) << size << " bytes EIP-8 ack from";
215215
m_ackCipher.resize((size_t)size + 2);
216216
auto rest = ba::buffer(ba::buffer(m_ackCipher) + c_ackCipherSizeBytes);
@@ -245,12 +245,18 @@ void RLPXHandshake::cancel()
245245
m_io.reset();
246246
}
247247

248-
void RLPXHandshake::error()
248+
void RLPXHandshake::error(boost::system::error_code _ech)
249249
{
250+
stringstream errorStream;
251+
errorStream << "Handshake failed";
252+
if (_ech)
253+
errorStream << " (I/O error: " << _ech.message() << ")";
250254
if (remoteSocketConnected())
251-
LOG(m_logger) << "Disconnecting (Handshake Failed)";
255+
errorStream << ". Disconnecting...";
252256
else
253-
LOG(m_logger) << "Handshake Failed (Connection reset by peer)";
257+
errorStream << " (Connection reset by peer)";
258+
259+
LOG(m_logger) << errorStream.str();
254260

255261
cancel();
256262
}
@@ -262,12 +268,7 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
262268

263269
if (_ech || m_nextState == Error || m_cancel)
264270
{
265-
stringstream errorStream;
266-
errorStream << "Handshake Failed ";
267-
if (_ech)
268-
errorStream << "(I/O Error: " << _ech.message() << ")";
269-
LOG(m_logger) << errorStream.str();
270-
return error();
271+
return error(_ech);
271272
}
272273

273274
auto self(shared_from_this());

libp2p/RLPxHandshake.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class RLPXHandshake: public std::enable_shared_from_this<RLPXHandshake>
9090
void readAckEIP8();
9191

9292
/// Closes connection and ends transitions.
93-
void error();
94-
93+
void error(boost::system::error_code _ech = boost::system::error_code());
94+
9595
/// Performs transition for m_nextState.
9696
virtual void transition(boost::system::error_code _ech = boost::system::error_code());
9797

0 commit comments

Comments
 (0)