trunk: expose peer roster in /status.trunks[SECTION].nodes

Cache the most recent sanitized MsgTrunkNodeList per TrunkLink in
m_partner_nodes and surface it from statusJson() as trunks[X].nodes.
/status now matches the roster that was already flowing to MQTT
(nodes/<peer_id>) and Redis (pushPeerNode).

Cleared when the link goes fully inactive — single, paired inbound,
and paired outbound disconnect paths all check isActive() before
clearing so a single surviving inbound/outbound in a paired group
keeps the cache live. Redis tombstones are already handled by
Reflector::onTrunkStateChanged() and unchanged here.

Caveat (pre-existing): in PAIRED mode the two sources share one
peerId(), so the latest arrival overwrites the prior one — same
behaviour MQTT and Redis already have. Fixing that requires
per-connection peer_id attribution, out of scope for this patch.
This commit is contained in:
Audric committed 2026-04-19 00:02:58 +02:00
1 parent cadc5c5aa2
commit bf5af3eca0
3 files changed
+73

No files matched your search

+25
View File
@@ -512,6 +512,22 @@ Json::Value TrunkLink::statusJson(void) const
for (const auto& cs : m_muted_callsigns) muted_arr.append(cs);
obj["muted"] = muted_arr;
Json::Value nodes_arr(Json::arrayValue);
for (const auto& n : m_partner_nodes)
{
Json::Value entry(Json::objectValue);
entry["callsign"] = n.callsign;
entry["tg"] = static_cast<Json::UInt>(n.tg);
if (n.lat != 0.0f || n.lon != 0.0f)
{
entry["lat"] = n.lat;
entry["lon"] = n.lon;
}
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
nodes_arr.append(entry);
}
obj["nodes"] = nodes_arr;
return obj;
} /* TrunkLink::statusJson */
@@ -644,6 +660,8 @@ void TrunkLink::onInboundDisconnected(Async::FramedTcpConnection* con,
// Emit after state is cleared so isActive()-based cleanup in consumers
// (e.g. Redis peer-node mirror) sees the correct post-disconnect state.
m_reflector->onTrunkStateChanged(m_section, peerId(), "inbound", false);
if (!isActive()) m_partner_nodes.clear();
} /* TrunkLink::onInboundDisconnected */
@@ -766,6 +784,8 @@ void TrunkLink::onDisconnected(TcpConnection* con,
// sees the correct post-disconnect state.
m_reflector->onTrunkStateChanged(m_section, peerId(), "outbound", false);
if (!isActive()) m_partner_nodes.clear();
// TcpPrioClient auto-reconnects — nothing else to do
} /* TrunkLink::onDisconnected */
@@ -1450,6 +1470,8 @@ void TrunkLink::onPairedInboundDisconnected(Async::FramedTcpConnection* con,
m_ib_cons.erase(m_ib_cons.begin() + idx);
m_ib_states.erase(m_ib_states.begin() + idx);
// Reflector owns the connection object — do NOT delete it here.
if (!isActive()) m_partner_nodes.clear();
} /* TrunkLink::onPairedInboundDisconnected */
@@ -1494,6 +1516,8 @@ void TrunkLink::onPairedOutboundDisconnected(FramedTcpClient* client,
{
m_sticky_ob_idx = (idx + 1) % m_ob_cons.size();
}
if (!isActive()) m_partner_nodes.clear();
// TcpPrioClient auto-reconnects; sticky may switch back here next send.
} /* TrunkLink::onPairedOutboundDisconnected */
@@ -1738,6 +1762,7 @@ void TrunkLink::handleMsgTrunkNodeList(std::istream& is)
}
m_reflector->onPeerNodeList(peerId(), sanitized);
m_partner_nodes = std::move(sanitized);
} /* TrunkLink::handleMsgTrunkNodeList */
+5
View File
@@ -204,6 +204,11 @@ class TrunkLink : public sigc::trackable
// TGs currently held by this specific trunk peer (for scoped cleanup)
std::set<uint32_t> m_peer_active_tgs;
// Most recent MsgTrunkNodeList we received from the peer, sanitized.
// Surfaced in statusJson() so /status can attribute nodes to a peer.
// Cleared when the link goes fully inactive.
std::vector<MsgTrunkNodeList::NodeEntry> m_partner_nodes;
// TGs the peer has shown interest in (sent TalkerStart for).
// Maps TG number to last activity timestamp. Entries expire after
// PEER_INTEREST_TIMEOUT_S seconds of inactivity.