|
|
@ -943,7 +943,7 @@ namespace transport |
|
|
|
m_LastActivityTimestamp = i2p::util::GetSecondsSinceEpoch (); |
|
|
|
m_LastActivityTimestamp = i2p::util::GetSecondsSinceEpoch (); |
|
|
|
m_NumSentBytes += bytes_transferred; |
|
|
|
m_NumSentBytes += bytes_transferred; |
|
|
|
i2p::transport::transports.UpdateSentBytes (bytes_transferred); |
|
|
|
i2p::transport::transports.UpdateSentBytes (bytes_transferred); |
|
|
|
LogPrint (eLogDebug, "NTCP2: Next frame sent"); |
|
|
|
LogPrint (eLogDebug, "NTCP2: Next frame sent ", bytes_transferred); |
|
|
|
SendQueue (); |
|
|
|
SendQueue (); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -969,13 +969,13 @@ namespace transport |
|
|
|
len += 3; |
|
|
|
len += 3; |
|
|
|
totalLen += len; |
|
|
|
totalLen += len; |
|
|
|
encryptBufs.push_back (std::make_pair (buf, len)); |
|
|
|
encryptBufs.push_back (std::make_pair (buf, len)); |
|
|
|
if (it == *msgs.begin ()) // first message
|
|
|
|
if (&it == &msgs.front ()) // first message
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// allocate two bytes for length
|
|
|
|
// allocate two bytes for length
|
|
|
|
buf -= 2; len += 2; |
|
|
|
buf -= 2; len += 2; |
|
|
|
first = it; |
|
|
|
first = it; |
|
|
|
} |
|
|
|
} |
|
|
|
if (it == *msgs.rbegin () && it->len + 16 < it->maxLen) // last message
|
|
|
|
if (&it == &msgs.back () && it->len + 16 < it->maxLen) // last message
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// if it's long enough we add padding and MAC to it
|
|
|
|
// if it's long enough we add padding and MAC to it
|
|
|
|
// create padding block
|
|
|
|
// create padding block
|
|
|
@ -1023,41 +1023,6 @@ namespace transport |
|
|
|
void NTCP2Session::SendQueue () |
|
|
|
void NTCP2Session::SendQueue () |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_SendQueue.empty ()) |
|
|
|
if (!m_SendQueue.empty ()) |
|
|
|
{ |
|
|
|
|
|
|
|
auto buf = m_Server.NewNTCP2FrameBuffer (); |
|
|
|
|
|
|
|
uint8_t * payload = buf->data (); |
|
|
|
|
|
|
|
size_t s = 0; |
|
|
|
|
|
|
|
// add I2NP blocks
|
|
|
|
|
|
|
|
while (!m_SendQueue.empty ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto msg = m_SendQueue.front (); |
|
|
|
|
|
|
|
size_t len = msg->GetNTCP2Length (); |
|
|
|
|
|
|
|
if (s + len + 3 <= NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) // 3 bytes block header
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
payload[s] = eNTCP2BlkI2NPMessage; // blk
|
|
|
|
|
|
|
|
htobe16buf (payload + s + 1, len); // size
|
|
|
|
|
|
|
|
s += 3; |
|
|
|
|
|
|
|
msg->ToNTCP2 (); |
|
|
|
|
|
|
|
memcpy (payload + s, msg->GetNTCP2Header (), len); |
|
|
|
|
|
|
|
s += len; |
|
|
|
|
|
|
|
m_SendQueue.pop_front (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (len + 3 > NTCP2_UNENCRYPTED_FRAME_MAX_SIZE) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "NTCP2: I2NP message of size ", len, " can't be sent. Dropped"); |
|
|
|
|
|
|
|
m_SendQueue.pop_front (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// add padding block
|
|
|
|
|
|
|
|
s += CreatePaddingBlock (s, payload + s, NTCP2_UNENCRYPTED_FRAME_MAX_SIZE - s); |
|
|
|
|
|
|
|
// send
|
|
|
|
|
|
|
|
SendNextFrame (payload, s); |
|
|
|
|
|
|
|
m_Server.DeleteNTCP2FrameBuffer (buf); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* if (!m_SendQueue.empty ())
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<std::shared_ptr<I2NPMessage> > msgs; |
|
|
|
std::vector<std::shared_ptr<I2NPMessage> > msgs; |
|
|
|
size_t s = 0; |
|
|
|
size_t s = 0; |
|
|
@ -1080,7 +1045,7 @@ namespace transport |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
SendI2NPMsgs (msgs); |
|
|
|
SendI2NPMsgs (msgs); |
|
|
|
} */ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
size_t NTCP2Session::CreatePaddingBlock (size_t msgLen, uint8_t * buf, size_t len) |
|
|
|
size_t NTCP2Session::CreatePaddingBlock (size_t msgLen, uint8_t * buf, size_t len) |
|
|
|