1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-11 13:27:52 +00:00

precalculate padding sizes

This commit is contained in:
orignal 2021-07-15 19:01:43 -04:00
parent cd0751d3f1
commit 0cd9f1b002
2 changed files with 14 additions and 2 deletions

View File

@ -332,7 +332,8 @@ namespace transport
m_SendMDCtx(nullptr), m_ReceiveMDCtx (nullptr),
#endif
m_NextReceivedLen (0), m_NextReceivedBuffer (nullptr), m_NextSendBuffer (nullptr),
m_ReceiveSequenceNumber (0), m_SendSequenceNumber (0), m_IsSending (false)
m_ReceiveSequenceNumber (0), m_SendSequenceNumber (0), m_IsSending (false),
m_NextPaddingSize (16)
{
if (in_RemoteRouter) // Alice
{
@ -1058,7 +1059,15 @@ namespace transport
size_t paddingSize = (msgLen*NTCP2_MAX_PADDING_RATIO)/100;
if (msgLen + paddingSize + 3 > NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) paddingSize = NTCP2_UNENCRYPTED_FRAME_MAX_SIZE - msgLen -3;
if (paddingSize > len) paddingSize = len;
if (paddingSize) paddingSize = rand () % paddingSize;
if (paddingSize)
{
if (m_NextPaddingSize >= 16)
{
RAND_bytes ((uint8_t *)m_PaddingSizes, sizeof (m_PaddingSizes));
m_NextPaddingSize = 0;
}
paddingSize = m_PaddingSizes[m_NextPaddingSize++] % paddingSize;
}
buf[0] = eNTCP2BlkPadding; // blk
htobe16buf (buf + 1, paddingSize); // size
memset (buf + 3, 0, paddingSize);

View File

@ -218,6 +218,9 @@ namespace transport
bool m_IsSending;
std::list<std::shared_ptr<I2NPMessage> > m_SendQueue;
uint64_t m_NextRouterInfoResendTime; // seconds since epoch
uint16_t m_PaddingSizes[16];
int m_NextPaddingSize;
};
class NTCP2Server: private i2p::util::RunnableServiceWithWork