mirror of https://github.com/infosecn1nja/C3.git
QualityOfService::PushReceivedChunk returns true if chunk was accpted
parent
307602b85e
commit
28cad0a4f1
|
@ -114,8 +114,9 @@ namespace FSecure::C3::Linter
|
|||
std::this_thread::sleep_for(GetDevice()->GetUpdateDelay());
|
||||
for (auto&& chunk : std::static_pointer_cast<C3::AbstractChannel>(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));
|
||||
}
|
||||
|
|
|
@ -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<uint32_t, uint32_t, uint32_t>();
|
||||
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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue