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

Method ReceivePacket

src/test/net_tests.cpp:1254–1283  ·  view source on GitHub ↗

Expect a packet to have been received from transport, process it, and return its contents * (only after ReceiveKey). Decoys are skipped. Optional associated authenticated data (AAD) is * expected in the first received packet, no matter if that is a decoy or not. */

Source from the content-addressed store, hash-verified

1252 * (only after ReceiveKey). Decoys are skipped. Optional associated authenticated data (AAD) is
1253 * expected in the first received packet, no matter if that is a decoy or not. */
1254 std::vector<uint8_t> ReceivePacket(std::span<const std::byte> aad = {})
1255 {
1256 std::vector<uint8_t> contents;
1257 // Loop as long as there are ignored packets that are to be skipped.
1258 while (true) {
1259 // When processing a packet, at least enough bytes for its length descriptor must be received.
1260 BOOST_REQUIRE(m_received.size() >= BIP324Cipher::LENGTH_LEN);
1261 // Decrypt the content length.
1262 size_t size = m_cipher.DecryptLength(MakeByteSpan(std::span{m_received}.first(BIP324Cipher::LENGTH_LEN)));
1263 // Check that the full packet is in the receive buffer.
1264 BOOST_REQUIRE(m_received.size() >= size + BIP324Cipher::EXPANSION);
1265 // Decrypt the packet contents.
1266 contents.resize(size);
1267 bool ignore{false};
1268 bool ret = m_cipher.Decrypt(
1269 /*input=*/MakeByteSpan(
1270 std::span{m_received}.first(size + BIP324Cipher::EXPANSION).subspan(BIP324Cipher::LENGTH_LEN)),
1271 /*aad=*/aad,
1272 /*ignore=*/ignore,
1273 /*contents=*/MakeWritableByteSpan(contents));
1274 BOOST_CHECK(ret);
1275 // Don't expect AAD in further packets.
1276 aad = {};
1277 // Strip the processed packet's bytes off the front of the receive buffer.
1278 m_received.erase(m_received.begin(), m_received.begin() + size + BIP324Cipher::EXPANSION);
1279 // Stop if the ignore bit is not set on this packet.
1280 if (!ignore) break;
1281 }
1282 return contents;
1283 }
1284
1285 /** Expect garbage and garbage terminator to have been received, and process them (only after
1286 * ReceiveKey). */

Callers

nothing calls this directly

Calls 8

MakeByteSpanFunction · 0.85
MakeWritableByteSpanFunction · 0.85
DecryptLengthMethod · 0.80
sizeMethod · 0.45
resizeMethod · 0.45
DecryptMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected