diff --git a/src/svxlink/reflector/TrunkLink.cpp b/src/svxlink/reflector/TrunkLink.cpp index 46edd65..36e4e50 100644 --- a/src/svxlink/reflector/TrunkLink.cpp +++ b/src/svxlink/reflector/TrunkLink.cpp @@ -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(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 */ diff --git a/src/svxlink/reflector/TrunkLink.h b/src/svxlink/reflector/TrunkLink.h index af2a38f..10e24df 100644 --- a/src/svxlink/reflector/TrunkLink.h +++ b/src/svxlink/reflector/TrunkLink.h @@ -204,6 +204,11 @@ class TrunkLink : public sigc::trackable // TGs currently held by this specific trunk peer (for scoped cleanup) std::set 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 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. diff --git a/tests/test_trunk.py b/tests/test_trunk.py index 7519a19..47601b3 100644 --- a/tests/test_trunk.py +++ b/tests/test_trunk.py @@ -1706,6 +1706,49 @@ class TestTrunkIntegration(unittest.TestCase): finally: 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.
.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 # ------------------------------------------------------------------