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); for (const auto& cs : m_muted_callsigns) muted_arr.append(cs);
obj["muted"] = muted_arr; 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; return obj;
} /* TrunkLink::statusJson */ } /* TrunkLink::statusJson */
@@ -644,6 +660,8 @@ void TrunkLink::onInboundDisconnected(Async::FramedTcpConnection* con,
// Emit after state is cleared so isActive()-based cleanup in consumers // Emit after state is cleared so isActive()-based cleanup in consumers
// (e.g. Redis peer-node mirror) sees the correct post-disconnect state. // (e.g. Redis peer-node mirror) sees the correct post-disconnect state.
m_reflector->onTrunkStateChanged(m_section, peerId(), "inbound", false); m_reflector->onTrunkStateChanged(m_section, peerId(), "inbound", false);
if (!isActive()) m_partner_nodes.clear();
} /* TrunkLink::onInboundDisconnected */ } /* TrunkLink::onInboundDisconnected */
@@ -766,6 +784,8 @@ void TrunkLink::onDisconnected(TcpConnection* con,
// sees the correct post-disconnect state. // sees the correct post-disconnect state.
m_reflector->onTrunkStateChanged(m_section, peerId(), "outbound", false); m_reflector->onTrunkStateChanged(m_section, peerId(), "outbound", false);
if (!isActive()) m_partner_nodes.clear();
// TcpPrioClient auto-reconnects — nothing else to do // TcpPrioClient auto-reconnects — nothing else to do
} /* TrunkLink::onDisconnected */ } /* TrunkLink::onDisconnected */
@@ -1450,6 +1470,8 @@ void TrunkLink::onPairedInboundDisconnected(Async::FramedTcpConnection* con,
m_ib_cons.erase(m_ib_cons.begin() + idx); m_ib_cons.erase(m_ib_cons.begin() + idx);
m_ib_states.erase(m_ib_states.begin() + idx); m_ib_states.erase(m_ib_states.begin() + idx);
// Reflector owns the connection object — do NOT delete it here. // Reflector owns the connection object — do NOT delete it here.
if (!isActive()) m_partner_nodes.clear();
} /* TrunkLink::onPairedInboundDisconnected */ } /* TrunkLink::onPairedInboundDisconnected */
@@ -1494,6 +1516,8 @@ void TrunkLink::onPairedOutboundDisconnected(FramedTcpClient* client,
{ {
m_sticky_ob_idx = (idx + 1) % m_ob_cons.size(); 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. // TcpPrioClient auto-reconnects; sticky may switch back here next send.
} /* TrunkLink::onPairedOutboundDisconnected */ } /* TrunkLink::onPairedOutboundDisconnected */
@@ -1738,6 +1762,7 @@ void TrunkLink::handleMsgTrunkNodeList(std::istream& is)
} }
m_reflector->onPeerNodeList(peerId(), sanitized); m_reflector->onPeerNodeList(peerId(), sanitized);
m_partner_nodes = std::move(sanitized);
} /* TrunkLink::handleMsgTrunkNodeList */ } /* 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) // TGs currently held by this specific trunk peer (for scoped cleanup)
std::set<uint32_t> m_peer_active_tgs; 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). // TGs the peer has shown interest in (sent TalkerStart for).
// Maps TG number to last activity timestamp. Entries expire after // Maps TG number to last activity timestamp. Entries expire after
// PEER_INTEREST_TIMEOUT_S seconds of inactivity. // PEER_INTEREST_TIMEOUT_S seconds of inactivity.
+43
View File
@@ -1706,6 +1706,49 @@ class TestTrunkIntegration(unittest.TestCase):
finally: finally:
rx.close() rx.close()
# ------------------------------------------------------------------
# Test 27b: Trunk peer's roster visible in /status.trunks[X].nodes
# ------------------------------------------------------------------
def test_27b_trunk_peer_roster_in_status(self):
"""A client logged in on the primary reflector appears under
/status.trunks.<SECTION>.nodes on a trunk peer — symmetric with the
twin-partner roster (trunks should expose the same info we already
push to MQTT and Redis).
"""
# Pick any peer that trunks to the primary
peer = next(n for n in REFLECTOR_NAMES if n != self.PRIMARY)
section = T.trunk_section_name(peer, self.PRIMARY)
client = ClientPeer()
try:
port = T.mapped_client_port(self.PRIMARY)
client.connect(HOST, port)
client.authenticate(callsign=CLIENT_CALLSIGN,
password=CLIENT_PASSWORD)
def callsign_on_peer():
status = get_status(*_http(peer))
trunk = status.get("trunks", {}).get(section, {})
nodes = trunk.get("nodes", [])
return any(n.get("callsign") == CLIENT_CALLSIGN for n in nodes)
wait_until(callsign_on_peer, timeout=5.0, interval=0.25,
msg=f"{CLIENT_CALLSIGN} did not appear in {peer}'s "
f"/status.trunks.{section}.nodes after login on "
f"{self.PRIMARY}")
finally:
client.close()
def callsign_gone_from_peer():
status = get_status(*_http(peer))
trunk = status.get("trunks", {}).get(section, {})
nodes = trunk.get("nodes", [])
return not any(n.get("callsign") == CLIENT_CALLSIGN for n in nodes)
wait_until(callsign_gone_from_peer, timeout=5.0, interval=0.25,
msg=f"{CLIENT_CALLSIGN} still in {peer}'s "
f"/status.trunks.{section}.nodes after disconnect")
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Test 28: MQTT client connect/disconnect events # Test 28: MQTT client connect/disconnect events
# ------------------------------------------------------------------ # ------------------------------------------------------------------