From 28cad0a4f114d8f627642af399d1fdf964d4cb8d Mon Sep 17 00:00:00 2001 From: Pawel Kurowski Date: Fri, 22 May 2020 15:15:36 +0200 Subject: [PATCH] QualityOfService::PushReceivedChunk returns true if chunk was accpted --- Src/ChannelLinter/MockDeviceBridge.cpp | 5 +++-- Src/Core/QualityOfService.cpp | 12 +++++++----- Src/Core/QualityOfService.h | 6 ++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Src/ChannelLinter/MockDeviceBridge.cpp b/Src/ChannelLinter/MockDeviceBridge.cpp index 9a12bda..0895aa5 100644 --- a/Src/ChannelLinter/MockDeviceBridge.cpp +++ b/Src/ChannelLinter/MockDeviceBridge.cpp @@ -114,8 +114,9 @@ namespace FSecure::C3::Linter std::this_thread::sleep_for(GetDevice()->GetUpdateDelay()); for (auto&& chunk : std::static_pointer_cast(GetDevice())->OnReceiveFromChannelInternal()) { - noProgressCounter = 0; - m_QoS.PushReceivedChunk(chunk); + if (m_QoS.PushReceivedChunk(chunk)) + noProgressCounter = 0; + if (auto packet = m_QoS.GetNextPacket(); !packet.empty()) // this form will ensure that packets are returned in same order they are available. packets.emplace_back(std::move(packet)); } diff --git a/Src/Core/QualityOfService.cpp b/Src/Core/QualityOfService.cpp index dc09047..2b6a457 100644 --- a/Src/Core/QualityOfService.cpp +++ b/Src/Core/QualityOfService.cpp @@ -22,20 +22,20 @@ FSecure::ByteVector FSecure::C3::QualityOfService::GetNextPacket() } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void FSecure::C3::QualityOfService::PushReceivedChunk(ByteView chunkWithHeader) +bool FSecure::C3::QualityOfService::PushReceivedChunk(ByteView chunkWithHeader) { if (chunkWithHeader.size() <= QualityOfService::s_HeaderSize) // Data is to short to even be chunk of packet. - return; // skip this chunk. there is nothing that can be done with it. If sender knows it pushed chunk to short it will retransmit it. + return false; // skip this chunk. there is nothing that can be done with it. If sender knows it pushed chunk to short it will retransmit it. auto [mId, cId, expectedSize] = chunkWithHeader.Read(); - PushReceivedChunk(mId, cId, expectedSize, chunkWithHeader); + return PushReceivedChunk(mId, cId, expectedSize, chunkWithHeader); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void FSecure::C3::QualityOfService::PushReceivedChunk(uint32_t packetId, uint32_t chunkId, uint32_t expectedSize, ByteView chunk) +bool FSecure::C3::QualityOfService::PushReceivedChunk(uint32_t packetId, uint32_t chunkId, uint32_t expectedSize, ByteView chunk) { if (chunk.size() < QualityOfService::s_MinBodySize && chunk.size() != expectedSize) - return; + return false; auto it = m_ReciveQueue.find(packetId); if (it == m_ReciveQueue.end()) @@ -45,6 +45,8 @@ void FSecure::C3::QualityOfService::PushReceivedChunk(uint32_t packetId, uint32_ if (chunkId == 0) it->second.SetExpectedSize(expectedSize); + + return true; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Src/Core/QualityOfService.h b/Src/Core/QualityOfService.h index 74bc9f1..58b7b8a 100644 --- a/Src/Core/QualityOfService.h +++ b/Src/Core/QualityOfService.h @@ -106,14 +106,16 @@ namespace FSecure::C3 /// Push chunk to QoS storage to handle merging and ordering. /// @param chunkWithHeader received packet. Device will add QoS header before sending any chunk. - void PushReceivedChunk(ByteView chunkWithHeader); + /// @return true if chunk was accepted. + bool PushReceivedChunk(ByteView chunkWithHeader); /// Push chunk to QoS storage to handle merging and ordering. /// @param packetId id of the packet. /// @param chunkId id of the chunk. /// @param expectedSize expected size of whole packet. /// @param chunk chunk of packet. - void PushReceivedChunk(uint32_t packetId, uint32_t chunkId, uint32_t expectedSize, ByteView chunk); + /// @return true if chunk was accepted. + bool PushReceivedChunk(uint32_t packetId, uint32_t chunkId, uint32_t expectedSize, ByteView chunk); /// Get Packet Splitter for data to be sent through channel. PacketSplitter GetPacketSplitter(ByteView data);