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

Commit f1f5db3

Browse files
committed
Set handshake failure reason in EIP8 code paths
1 parent 06b00ce commit f1f5db3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

libp2p/RLPxHandshake.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ void RLPXHandshake::writeAckEIP8()
112112
m_ackCipher.insert(m_ackCipher.begin(), prefix.begin(), prefix.end());
113113

114114
auto self(shared_from_this());
115-
ba::async_write(m_socket->ref(), ba::buffer(m_ackCipher), [this, self](boost::system::error_code ec, std::size_t)
116-
{
117-
transition(ec);
118-
});
115+
ba::async_write(m_socket->ref(), ba::buffer(m_ackCipher),
116+
[this, self](boost::system::error_code ec, std::size_t) {
117+
if (ec)
118+
m_failureReason = TcpError;
119+
transition(ec);
120+
});
119121
}
120122

121123
void RLPXHandshake::setAuthValues(Signature const& _sig, Public const& _remotePubk, h256 const& _remoteNonce, uint64_t _remoteVersion)
@@ -163,7 +165,10 @@ void RLPXHandshake::readAuthEIP8()
163165
{
164166
bytesConstRef ct(&m_authCipher);
165167
if (ec)
168+
{
169+
m_failureReason = TcpError;
166170
transition(ec);
171+
}
167172
else if (decryptECIES(m_host->m_alias.secret(), ct.cropped(0, 2), ct.cropped(2), m_auth))
168173
{
169174
RLP rlp(m_auth, RLP::ThrowOnFail | RLP::FailIfTooSmall);
@@ -180,6 +185,7 @@ void RLPXHandshake::readAuthEIP8()
180185
{
181186
LOG(m_logger) << "EIP-8 auth decrypt failed";
182187
m_nextState = Error;
188+
m_failureReason = FrameDecryptionFailure;
183189
transition();
184190
}
185191
});
@@ -192,7 +198,10 @@ void RLPXHandshake::readAck()
192198
ba::async_read(m_socket->ref(), ba::buffer(m_ackCipher, c_ackCipherSizeBytes),
193199
[this, self](boost::system::error_code ec, std::size_t) {
194200
if (ec)
201+
{
202+
m_failureReason = TcpError;
195203
transition(ec);
204+
}
196205
else if (decryptECIES(m_host->m_alias.secret(), bytesConstRef(&m_ackCipher), m_ack))
197206
{
198207
LOG(m_logger) << "ack from";
@@ -218,7 +227,10 @@ void RLPXHandshake::readAckEIP8()
218227
{
219228
bytesConstRef ct(&m_ackCipher);
220229
if (ec)
230+
{
231+
m_failureReason = TcpError;
221232
transition(ec);
233+
}
222234
else if (decryptECIES(m_host->m_alias.secret(), ct.cropped(0, 2), ct.cropped(2), m_ack))
223235
{
224236
RLP rlp(m_ack, RLP::ThrowOnFail | RLP::FailIfTooSmall);
@@ -230,6 +242,7 @@ void RLPXHandshake::readAckEIP8()
230242
else
231243
{
232244
LOG(m_logger) << "EIP-8 ack decrypt failed";
245+
m_failureReason = FrameDecryptionFailure;
233246
m_nextState = Error;
234247
transition();
235248
}

0 commit comments

Comments
 (0)