|
|
@ -368,9 +368,9 @@ namespace transport |
|
|
|
size_t moreBytes = socket.available (ec); |
|
|
|
size_t moreBytes = socket.available (ec); |
|
|
|
if (!ec && moreBytes) |
|
|
|
if (!ec && moreBytes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<Packet *> packets; |
|
|
|
auto packets = m_PacketsArrayPool.AcquireMt (); |
|
|
|
packets.push_back (packet); |
|
|
|
packets->AddPacket (packet); |
|
|
|
while (moreBytes && packets.size () < SSU2_MAX_NUM_PACKETS_PER_BATCH) |
|
|
|
while (moreBytes && packets->numPackets < SSU2_MAX_NUM_PACKETS_PER_BATCH) |
|
|
|
{ |
|
|
|
{ |
|
|
|
packet = m_PacketsPool.AcquireMt (); |
|
|
|
packet = m_PacketsPool.AcquireMt (); |
|
|
|
packet->len = socket.receive_from (boost::asio::buffer (packet->buf, SSU2_MAX_PACKET_SIZE), packet->from, 0, ec); |
|
|
|
packet->len = socket.receive_from (boost::asio::buffer (packet->buf, SSU2_MAX_PACKET_SIZE), packet->from, 0, ec); |
|
|
@ -378,7 +378,13 @@ namespace transport |
|
|
|
{ |
|
|
|
{ |
|
|
|
i2p::transport::transports.UpdateReceivedBytes (packet->len); |
|
|
|
i2p::transport::transports.UpdateReceivedBytes (packet->len); |
|
|
|
if (packet->len >= SSU2_MIN_RECEIVED_PACKET_SIZE) |
|
|
|
if (packet->len >= SSU2_MIN_RECEIVED_PACKET_SIZE) |
|
|
|
packets.push_back (packet); |
|
|
|
{ |
|
|
|
|
|
|
|
if (!packets->AddPacket (packet)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "SSU2: Received packets array is full"); |
|
|
|
|
|
|
|
m_PacketsPool.ReleaseMt (packet); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else // drop too short packets
|
|
|
|
else // drop too short packets
|
|
|
|
m_PacketsPool.ReleaseMt (packet); |
|
|
|
m_PacketsPool.ReleaseMt (packet); |
|
|
|
moreBytes = socket.available(ec); |
|
|
|
moreBytes = socket.available(ec); |
|
|
@ -391,10 +397,7 @@ namespace transport |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
GetService ().post ([packets = std::move (packets), this]() mutable |
|
|
|
GetService ().post (std::bind (&SSU2Server::HandleReceivedPackets, this, packets)); |
|
|
|
{ |
|
|
|
|
|
|
|
HandleReceivedPackets (std::move (packets)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
GetService ().post (std::bind (&SSU2Server::HandleReceivedPacket, this, packet)); |
|
|
|
GetService ().post (std::bind (&SSU2Server::HandleReceivedPacket, this, packet)); |
|
|
@ -438,15 +441,23 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SSU2Server::HandleReceivedPackets (std::vector<Packet *>&& packets) |
|
|
|
void SSU2Server::HandleReceivedPackets (Packets * packets) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (!packets) return; |
|
|
|
if (m_IsThroughProxy) |
|
|
|
if (m_IsThroughProxy) |
|
|
|
for (auto& packet: packets) |
|
|
|
for (size_t i = 0; i < packets->numPackets; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto& packet = (*packets)[i]; |
|
|
|
ProcessNextPacketFromProxy (packet->buf, packet->len); |
|
|
|
ProcessNextPacketFromProxy (packet->buf, packet->len); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
for (auto& packet: packets) |
|
|
|
for (size_t i = 0; i < packets->numPackets; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto& packet = (*packets)[i]; |
|
|
|
ProcessNextPacket (packet->buf, packet->len, packet->from); |
|
|
|
ProcessNextPacket (packet->buf, packet->len, packet->from); |
|
|
|
m_PacketsPool.ReleaseMt (std::move (packets)); |
|
|
|
} |
|
|
|
|
|
|
|
m_PacketsPool.ReleaseMt (packets->data (), packets->numPackets); |
|
|
|
|
|
|
|
m_PacketsArrayPool.ReleaseMt (packets); |
|
|
|
if (m_LastSession && m_LastSession->GetState () != eSSU2SessionStateTerminated) |
|
|
|
if (m_LastSession && m_LastSession->GetState () != eSSU2SessionStateTerminated) |
|
|
|
m_LastSession->FlushData (); |
|
|
|
m_LastSession->FlushData (); |
|
|
|
} |
|
|
|
} |
|
|
@ -1098,6 +1109,7 @@ namespace transport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_PacketsPool.CleanUpMt (); |
|
|
|
m_PacketsPool.CleanUpMt (); |
|
|
|
|
|
|
|
m_PacketsArrayPool.CleanUpMt (); |
|
|
|
m_SentPacketsPool.CleanUp (); |
|
|
|
m_SentPacketsPool.CleanUp (); |
|
|
|
m_IncompleteMessagesPool.CleanUp (); |
|
|
|
m_IncompleteMessagesPool.CleanUp (); |
|
|
|
m_FragmentsPool.CleanUp (); |
|
|
|
m_FragmentsPool.CleanUp (); |
|
|
|