= Fix NXDN receive ordering in FNE

- Dispatch local NXDN packets through a dedicated single-worker queue
- Prevent voice frames overtaking their preceding call header
- Preserve existing dispatch for other protocols
pull/134/head
Dev_Ranger 3 weeks ago
parent 3ba67a1506
commit c68149421f

@ -164,6 +164,7 @@ TrafficNetwork::TrafficNetwork(HostFNE* host, const std::string& address, uint16
m_jitterMaxSize(4U),
m_jitterMaxWait(40000U),
m_threadPool(workerCnt, "fne"),
m_nxdnThreadPool(1U, "fne-nxdn"),
m_metadataUpdateThreadPool(workerCnt / 2U, "mupdt"),
m_healthDataPlaneEpoch(0U),
m_healthLastDataPlaneTick(0U),
@ -195,6 +196,10 @@ TrafficNetwork::TrafficNetwork(HostFNE* host, const std::string& address, uint16
assert(port > 0U);
assert(!password.empty());
// The general pool constructor enforces a minimum of four workers. NXDN
// needs one FIFO consumer so header decoding cannot be overtaken by voice.
m_nxdnThreadPool.setMaxWorkerCnt(1U);
m_peers.reserve(MAX_HARD_CONN_CAP);
m_peerReplicaPeers.reserve(MAX_HARD_CONN_CAP);
m_peerAffiliations.reserve(MAX_HARD_CONN_CAP);
@ -693,7 +698,12 @@ void TrafficNetwork::processNetwork()
m_healthLastTaskProgress.store(healthNow, std::memory_order_relaxed);
m_healthTasksSubmitted.fetch_add(1U, std::memory_order_relaxed);
if (!m_threadPool.enqueue(new_pooltask(taskNetworkRx, req))) {
// Serialize local NXDN before sequence verification and call-state updates.
// A mutex inside the handler would not preserve receive order.
const bool orderedNXDN = fneHeader.getFunction() == NET_FUNC::PROTOCOL &&
fneHeader.getSubFunction() == NET_SUBFUNC::PROTOCOL_SUBFUNC_NXDN;
ThreadPool& receivePool = orderedNXDN ? m_nxdnThreadPool : m_threadPool;
if (!receivePool.enqueue(new_pooltask(taskNetworkRx, req))) {
m_healthTaskEnqueueFailures.fetch_add(1U, std::memory_order_relaxed);
m_healthTasksCompleted.fetch_add(1U, std::memory_order_relaxed);
m_healthLastTaskProgress.store(healthNow, std::memory_order_relaxed);
@ -1006,6 +1016,7 @@ bool TrafficNetwork::open()
// start thread pool
m_threadPool.start();
m_nxdnThreadPool.start();
// start metadata thread pool
m_metadataUpdateThreadPool.start();
@ -1063,6 +1074,8 @@ void TrafficNetwork::close()
m_updateLookupTimer.stop();
// stop thread pool
m_nxdnThreadPool.stop();
m_nxdnThreadPool.wait();
m_threadPool.stop();
m_threadPool.wait();

@ -486,6 +486,8 @@ namespace network
uint32_t m_jitterMaxWait;
ThreadPool m_threadPool;
/** @brief Serial receive dispatcher preserving local NXDN packet arrival order. */
ThreadPool m_nxdnThreadPool;
ThreadPool m_metadataUpdateThreadPool;
// passive health telemetry -- these counters are intentionally lock-free so

Loading…
Cancel
Save

Powered by TurnKey Linux.