From e09e3980c97d81fb4cc49f7cfcc4bc27ce712227 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 12 Aug 2014 16:35:35 -0400 Subject: [PATCH] resend non-Acked packets together --- Streaming.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- Streaming.h | 3 ++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Streaming.cpp b/Streaming.cpp index fc4e8e99..d9730622 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -431,6 +431,54 @@ namespace stream return false; } + void Stream::SendPackets (const std::vector& packets) + { + if (!m_RemoteLeaseSet) + { + UpdateCurrentRemoteLease (); + if (!m_RemoteLeaseSet) + { + LogPrint ("Can't send packets. Missing remote LeaseSet"); + return; + } + } + + I2NPMessage * leaseSet = nullptr; + if (m_LeaseSetUpdated) + { + leaseSet = m_LocalDestination->GetLeaseSetMsg (); + m_LeaseSetUpdated = false; + } + + auto outboundTunnel = m_LocalDestination->GetTunnelPool ()->GetNextOutboundTunnel (); + if (outboundTunnel) + { + auto ts = i2p::util::GetMillisecondsSinceEpoch (); + if (ts >= m_CurrentRemoteLease.endDate) + UpdateCurrentRemoteLease (); + if (ts < m_CurrentRemoteLease.endDate) + { + std::vector msgs; + for (auto it: packets) + { + auto msg = i2p::garlic::routing.WrapMessage (*m_RemoteLeaseSet, + CreateDataMessage (this, it->GetBuffer (), it->GetLength ()), leaseSet); + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeTunnel, + m_CurrentRemoteLease.tunnelGateway, m_CurrentRemoteLease.tunnelID, + msg + }); + } + outboundTunnel->SendTunnelDataMsg (msgs); + } + else + LogPrint ("All leases are expired"); + } + else + LogPrint ("No outbound tunnels in the pool"); + } + void Stream::ScheduleResend () { m_ResendTimer.cancel (); @@ -443,17 +491,20 @@ namespace stream { if (ecode != boost::asio::error::operation_aborted) { + std::vector packets; for (auto it : m_SentPackets) { it->numResendAttempts++; if (it->numResendAttempts <= MAX_NUM_RESEND_ATTEMPTS) - SendPacket (it->GetBuffer (), it->GetLength ()); + packets.push_back (it); else { Close (); return; } } + if (packets.size () > 0) + SendPackets (packets); ScheduleResend (); } } diff --git a/Streaming.h b/Streaming.h index 86e80aef..ea6443c8 100644 --- a/Streaming.h +++ b/Streaming.h @@ -103,7 +103,8 @@ namespace stream void SendQuickAck (); bool SendPacket (Packet * packet); - bool SendPacket (const uint8_t * buf, size_t len); + bool SendPacket (const uint8_t * buf, size_t len); // TODO: remove + void SendPackets (const std::vector& packets); void SavePacket (Packet * packet); void ProcessPacket (Packet * packet);