35
35
#include < util/threadinterrupt.h>
36
36
#include < util/trace.h>
37
37
#include < util/translation.h>
38
+ #include < util/vector.h>
38
39
39
40
#ifdef WIN32
40
41
#include < string.h>
@@ -899,8 +900,7 @@ void V1Transport::MarkBytesSent(size_t bytes_sent) noexcept
899
900
m_bytes_sent = 0 ;
900
901
} else if (!m_sending_header && m_bytes_sent == m_message_to_send.data .size ()) {
901
902
// We're done sending a message's data. Wipe the data vector to reduce memory consumption.
902
- m_message_to_send.data .clear ();
903
- m_message_to_send.data .shrink_to_fit ();
903
+ ClearShrink (m_message_to_send.data );
904
904
m_bytes_sent = 0 ;
905
905
}
906
906
}
@@ -1123,8 +1123,8 @@ void V2Transport::ProcessReceivedMaybeV1Bytes() noexcept
1123
1123
SetReceiveState (RecvState::V1);
1124
1124
SetSendState (SendState::V1);
1125
1125
// Reset v2 transport buffers to save memory.
1126
- m_recv_buffer = {} ;
1127
- m_send_buffer = {} ;
1126
+ ClearShrink ( m_recv_buffer) ;
1127
+ ClearShrink ( m_send_buffer) ;
1128
1128
} else {
1129
1129
// We have not received enough to distinguish v1 from v2 yet. Wait until more bytes come.
1130
1130
}
@@ -1184,8 +1184,7 @@ bool V2Transport::ProcessReceivedKeyBytes() noexcept
1184
1184
/* ignore=*/ false ,
1185
1185
/* output=*/ MakeWritableByteSpan (m_send_buffer).last (BIP324Cipher::EXPANSION));
1186
1186
// We no longer need the garbage.
1187
- m_send_garbage.clear ();
1188
- m_send_garbage.shrink_to_fit ();
1187
+ ClearShrink (m_send_garbage);
1189
1188
1190
1189
// Construct version packet in the send buffer.
1191
1190
m_send_buffer.resize (m_send_buffer.size () + BIP324Cipher::EXPANSION + VERSION_CONTENTS.size ());
@@ -1275,7 +1274,7 @@ bool V2Transport::ProcessReceivedPacketBytes() noexcept
1275
1274
// Ignore flag does not matter for garbage authentication. Any valid packet functions
1276
1275
// as authentication. Receive and process the version packet next.
1277
1276
SetReceiveState (RecvState::VERSION);
1278
- m_recv_garbage = {} ;
1277
+ ClearShrink ( m_recv_garbage) ;
1279
1278
break ;
1280
1279
case RecvState::VERSION:
1281
1280
if (!ignore) {
@@ -1295,9 +1294,9 @@ bool V2Transport::ProcessReceivedPacketBytes() noexcept
1295
1294
Assume (false );
1296
1295
}
1297
1296
// Wipe the receive buffer where the next packet will be received into.
1298
- m_recv_buffer = {} ;
1297
+ ClearShrink ( m_recv_buffer) ;
1299
1298
// In all but APP_READY state, we can wipe the decoded contents.
1300
- if (m_recv_state != RecvState::APP_READY) m_recv_decode_buffer = {} ;
1299
+ if (m_recv_state != RecvState::APP_READY) ClearShrink ( m_recv_decode_buffer) ;
1301
1300
} else {
1302
1301
// We either have less than 3 bytes, so we don't know the packet's length yet, or more
1303
1302
// than 3 bytes but less than the packet's full ciphertext. Wait until those arrive.
@@ -1511,7 +1510,7 @@ CNetMessage V2Transport::GetReceivedMessage(std::chrono::microseconds time, bool
1511
1510
LogPrint (BCLog::NET, " V2 transport error: invalid message type (%u bytes contents), peer=%d\n " , m_recv_decode_buffer.size (), m_nodeid);
1512
1511
reject_message = true ;
1513
1512
}
1514
- m_recv_decode_buffer = {} ;
1513
+ ClearShrink ( m_recv_decode_buffer) ;
1515
1514
SetReceiveState (RecvState::APP);
1516
1515
1517
1516
return msg;
@@ -1545,7 +1544,7 @@ bool V2Transport::SetMessageToSend(CSerializedNetMsg& msg) noexcept
1545
1544
m_cipher.Encrypt (MakeByteSpan (contents), {}, false , MakeWritableByteSpan (m_send_buffer));
1546
1545
m_send_type = msg.m_type ;
1547
1546
// Release memory
1548
- msg.data = {} ;
1547
+ ClearShrink ( msg.data ) ;
1549
1548
return true ;
1550
1549
}
1551
1550
@@ -1577,7 +1576,7 @@ void V2Transport::MarkBytesSent(size_t bytes_sent) noexcept
1577
1576
// Wipe the buffer when everything is sent.
1578
1577
if (m_send_pos == m_send_buffer.size ()) {
1579
1578
m_send_pos = 0 ;
1580
- m_send_buffer = {} ;
1579
+ ClearShrink ( m_send_buffer) ;
1581
1580
}
1582
1581
}
1583
1582
0 commit comments