MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ProcessReceivedGarbageBytes

Method ProcessReceivedGarbageBytes

src/net.cpp:1185–1210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1183}
1184
1185bool V2Transport::ProcessReceivedGarbageBytes() noexcept
1186{
1187 AssertLockHeld(m_recv_mutex);
1188 Assume(m_recv_state == RecvState::GARB_GARBTERM);
1189 Assume(m_recv_buffer.size() <= MAX_GARBAGE_LEN + BIP324Cipher::GARBAGE_TERMINATOR_LEN);
1190 if (m_recv_buffer.size() >= BIP324Cipher::GARBAGE_TERMINATOR_LEN) {
1191 if (std::ranges::equal(MakeByteSpan(m_recv_buffer).last(BIP324Cipher::GARBAGE_TERMINATOR_LEN), m_cipher.GetReceiveGarbageTerminator())) {
1192 // Garbage terminator received. Store garbage to authenticate it as AAD later.
1193 m_recv_aad = std::move(m_recv_buffer);
1194 m_recv_aad.resize(m_recv_aad.size() - BIP324Cipher::GARBAGE_TERMINATOR_LEN);
1195 m_recv_buffer.clear();
1196 SetReceiveState(RecvState::VERSION);
1197 } else if (m_recv_buffer.size() == MAX_GARBAGE_LEN + BIP324Cipher::GARBAGE_TERMINATOR_LEN) {
1198 // We've reached the maximum length for garbage + garbage terminator, and the
1199 // terminator still does not match. Abort.
1200 LogDebug(BCLog::NET, "V2 transport error: missing garbage terminator, peer=%d\n", m_nodeid);
1201 return false;
1202 } else {
1203 // We still need to receive more garbage and/or garbage terminator bytes.
1204 }
1205 } else {
1206 // We have less than GARBAGE_TERMINATOR_LEN (16) bytes, so we certainly need to receive
1207 // more first.
1208 }
1209 return true;
1210}
1211
1212bool V2Transport::ProcessReceivedPacketBytes() noexcept
1213{

Callers

nothing calls this directly

Calls 5

MakeByteSpanFunction · 0.85
sizeMethod · 0.45
resizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected