validate incoming sequence number
This commit is contained in:
parent
eaac6084a2
commit
bb290ab7cb
@ -26,6 +26,8 @@
|
||||
#include "receiver.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace sACN {
|
||||
|
||||
/**
|
||||
@ -220,6 +222,29 @@ void Receiver::dataFrameHandler(ACN::PDU::Message<DATA::Pdu> frame) {
|
||||
if (source->sync_address != 0)
|
||||
subscribe(source->sync_address);
|
||||
|
||||
/// > \cite sACN 6.2.5 E1.31 Data Packet: Sequence Number
|
||||
/// > In a routed network environment it is possible for packets to be
|
||||
/// > received in a different order to the one in which they were sent. The
|
||||
/// > sequence number allows receivers or diagnostic equipment to detect out
|
||||
/// > of sequence or lost packets.
|
||||
/// Assume that sources transmitting a sequence number of 0 do not support
|
||||
/// sequencing.
|
||||
if (source->sequence_number != 0 && universe->provenance())
|
||||
{
|
||||
auto seq = source->sequence_number;
|
||||
auto old = universe->provenance()->sequence_number;
|
||||
auto hasWrapped = [seq, old] () {
|
||||
auto threshold = std::numeric_limits<typeof(old)>::max() * 0.9;
|
||||
if (seq < old && old > threshold)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
if (seq != old + 1)
|
||||
; // missed packet!
|
||||
if (seq <= old && !hasWrapped())
|
||||
return; // out of sequence packet!
|
||||
}
|
||||
|
||||
// PDU data will be a block of DMP
|
||||
auto block = static_cast<ACN::PDU::Block<ACN::DMP::Pdu>*>(frame->data());
|
||||
for (auto const &dmp : *block->pdu)
|
||||
|
Loading…
Reference in New Issue
Block a user