Move PacketSplitter to QualityOfService

dependabot/npm_and_yarn/Src/WebController/UI/elliptic-6.5.3
Pawel Kurowski 2020-05-20 14:04:10 +02:00
parent 8fee6a5fe2
commit 53fbc61764
2 changed files with 29 additions and 25 deletions

View File

@ -41,11 +41,6 @@ void FSecure::C3::QualityOfService::PushReceivedChunk(uint32_t packetId, uint32_
it->second.PushNextChunk(chunkId, expectedSize, ByteVector{ chunk });
}
FSecure::C3::PacketSplitter FSecure::C3::QualityOfService::GetPacketSplitter(ByteView data)
{
return { data, GetOutgouingPacketId() };
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FSecure::C3::QualityOfService::Packet::Packet(uint32_t chunkId, uint32_t expectedSize, ByteVector chunk)
: m_ExpectedSize(expectedSize)
@ -102,13 +97,21 @@ bool FSecure::C3::QualityOfService::Packet::IsReady()
return m_Size == m_ExpectedSize;
}
FSecure::C3::PacketSplitter::PacketSplitter(ByteView data, uint32_t id)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FSecure::C3::QualityOfService::PacketSplitter FSecure::C3::QualityOfService::GetPacketSplitter(ByteView data)
{
return { data, GetOutgouingPacketId() };
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FSecure::C3::QualityOfService::PacketSplitter::PacketSplitter(ByteView data, uint32_t id)
: m_Data{ data }, m_OryginalDataSize{ static_cast<uint32_t>(data.size()) }, m_PacketId{ id }, m_ChunkId{ 0 }
{
}
bool FSecure::C3::PacketSplitter::Update(size_t sent)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool FSecure::C3::QualityOfService::PacketSplitter::Update(size_t sent)
{
auto dataSent = sent - QualityOfService::s_HeaderSize;
if (sent < QualityOfService::s_MinFrameSize && dataSent != m_Data.size() )
@ -119,12 +122,14 @@ bool FSecure::C3::PacketSplitter::Update(size_t sent)
return true;
}
FSecure::ByteVector FSecure::C3::PacketSplitter::NextChunk() const
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FSecure::ByteVector FSecure::C3::QualityOfService::PacketSplitter::NextChunk() const
{
return ByteVector::Create(m_PacketId, m_ChunkId, m_OryginalDataSize).Concat(m_Data);
}
bool FSecure::C3::PacketSplitter::HasMore() const
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool FSecure::C3::QualityOfService::PacketSplitter::HasMore() const
{
return !m_Data.empty();
}

View File

@ -6,22 +6,6 @@
namespace FSecure::C3
{
class PacketSplitter
{
public:
PacketSplitter(ByteView data, uint32_t id);
bool Update(size_t sent);
ByteVector NextChunk() const;
bool HasMore() const;
private:
ByteView m_Data;
uint32_t m_OryginalDataSize;
uint32_t m_PacketId;
uint32_t m_ChunkId;
};
/// A structure that handles Quality of Service of C3 protocols.
class QualityOfService
{
@ -79,6 +63,21 @@ namespace FSecure::C3
static constexpr size_t s_MinFrameSize = 64U;
static constexpr size_t s_MinBodySize = s_MinFrameSize - s_HeaderSize;
class PacketSplitter
{
public:
PacketSplitter(ByteView data, uint32_t id);
bool Update(size_t sent);
ByteVector NextChunk() const;
bool HasMore() const;
private:
ByteView m_Data;
uint32_t m_OryginalDataSize;
uint32_t m_PacketId;
uint32_t m_ChunkId;
};
/// Get next packet.
/// @returns ByteVector whole packet when it's ready or empty buffer otherwise.
ByteVector GetNextPacket();