mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 17:37:53 +00:00
precalculate padding sizes
This commit is contained in:
parent
cd0751d3f1
commit
0cd9f1b002
@ -332,7 +332,8 @@ namespace transport
|
|||||||
m_SendMDCtx(nullptr), m_ReceiveMDCtx (nullptr),
|
m_SendMDCtx(nullptr), m_ReceiveMDCtx (nullptr),
|
||||||
#endif
|
#endif
|
||||||
m_NextReceivedLen (0), m_NextReceivedBuffer (nullptr), m_NextSendBuffer (nullptr),
|
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
|
if (in_RemoteRouter) // Alice
|
||||||
{
|
{
|
||||||
@ -1058,7 +1059,15 @@ namespace transport
|
|||||||
size_t paddingSize = (msgLen*NTCP2_MAX_PADDING_RATIO)/100;
|
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 (msgLen + paddingSize + 3 > NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) paddingSize = NTCP2_UNENCRYPTED_FRAME_MAX_SIZE - msgLen -3;
|
||||||
if (paddingSize > len) paddingSize = len;
|
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
|
buf[0] = eNTCP2BlkPadding; // blk
|
||||||
htobe16buf (buf + 1, paddingSize); // size
|
htobe16buf (buf + 1, paddingSize); // size
|
||||||
memset (buf + 3, 0, paddingSize);
|
memset (buf + 3, 0, paddingSize);
|
||||||
|
@ -218,6 +218,9 @@ namespace transport
|
|||||||
bool m_IsSending;
|
bool m_IsSending;
|
||||||
std::list<std::shared_ptr<I2NPMessage> > m_SendQueue;
|
std::list<std::shared_ptr<I2NPMessage> > m_SendQueue;
|
||||||
uint64_t m_NextRouterInfoResendTime; // seconds since epoch
|
uint64_t m_NextRouterInfoResendTime; // seconds since epoch
|
||||||
|
|
||||||
|
uint16_t m_PaddingSizes[16];
|
||||||
|
int m_NextPaddingSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NTCP2Server: private i2p::util::RunnableServiceWithWork
|
class NTCP2Server: private i2p::util::RunnableServiceWithWork
|
||||||
|
Loading…
Reference in New Issue
Block a user