From 05946125b55ba6214e04682c60c11435378fff56 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 13 Apr 2022 12:33:59 -0400 Subject: [PATCH] handle single packet --- libi2pd/SSU2.cpp | 23 +++++++++++++++++------ libi2pd/SSU2.h | 3 ++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/libi2pd/SSU2.cpp b/libi2pd/SSU2.cpp index 527e5273..8db82e92 100644 --- a/libi2pd/SSU2.cpp +++ b/libi2pd/SSU2.cpp @@ -1330,13 +1330,13 @@ namespace transport { i2p::transport::transports.UpdateReceivedBytes (bytes_transferred); packet->len = bytes_transferred; - std::vector packets; - packets.push_back (packet); boost::system::error_code ec; size_t moreBytes = socket.available (ec); - if (!ec) + if (!ec && moreBytes) { + std::vector packets; + packets.push_back (packet); while (moreBytes && packets.size () < 32) { packet = m_PacketsPool.AcquireMt (); @@ -1355,9 +1355,10 @@ namespace transport break; } } + GetService ().post (std::bind (&SSU2Server::HandleReceivedPackets, this, packets)); } - - GetService ().post (std::bind (&SSU2Server::HandleReceivedPacket, this, packets)); + else + GetService ().post (std::bind (&SSU2Server::HandleReceivedPacket, this, packet)); Receive (socket); } else @@ -1374,7 +1375,17 @@ namespace transport } } - void SSU2Server::HandleReceivedPacket (std::vector packets) + void SSU2Server::HandleReceivedPacket (Packet * packet) + { + if (packet) + { + ProcessNextPacket (packet->buf, packet->len, packet->from); + m_PacketsPool.ReleaseMt (packet); + if (m_LastSession) m_LastSession->FlushData (); + } + } + + void SSU2Server::HandleReceivedPackets (std::vector packets) { for (auto& packet: packets) ProcessNextPacket (packet->buf, packet->len, packet->from); diff --git a/libi2pd/SSU2.h b/libi2pd/SSU2.h index 13d149d9..8f60bc0d 100644 --- a/libi2pd/SSU2.h +++ b/libi2pd/SSU2.h @@ -257,7 +257,8 @@ namespace transport void Receive (boost::asio::ip::udp::socket& socket); void HandleReceivedFrom (const boost::system::error_code& ecode, size_t bytes_transferred, Packet * packet, boost::asio::ip::udp::socket& socket); - void HandleReceivedPacket (std::vector packets); + void HandleReceivedPacket (Packet * packet); + void HandleReceivedPackets (std::vector packets); void ProcessNextPacket (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); void ScheduleTermination ();