Fix bidirectional trunk routing and monitoring client notifications

Two bugs prevented real-world trunk conversations from working:

1. onTrunkTalkerUpdated only notified clients selected on a TG, not
   clients monitoring it. SvxLink repeaters monitoring a foreign TG
   never received MsgTalkerStart and could not auto-switch. Fixed by
   adding TgMonitorFilter to trunk talker broadcasts, matching the
   existing behavior of onTalkerUpdated for local talkers.

2. Trunk TG routing was one-way: when a client visited a foreign TG,
   isSharedTG forwarded to the owner, but the owner had no return
   path. Added per-link peer interest tracking — when a peer sends
   MsgTrunkTalkerStart for a TG, the receiving side records interest
   and forwards local activity on that TG back. Interest refreshes
   on audio, expires after 10 minutes idle, clears on disconnect.

New integration test verifies the full round-trip: client-A talks on
a foreign TG, monitoring client-B receives the notification, client-B
replies, and client-A receives audio back through the trunk.
This commit is contained in:
Audric committed 2026-03-28 19:09:38 +01:00
1 parent 8cf96f9ba5
commit accb4b3686
7 files changed
+200 -17

No files matched your search

+6 -2
View File
@@ -2440,7 +2440,9 @@ void Reflector::onTrunkTalkerUpdated(uint32_t tg,
broadcastMsg(MsgTalkerStop(tg, old_cs),
ReflectorClient::mkAndFilter(
ge_v2_client_filter,
ReflectorClient::TgFilter(tg)));
ReflectorClient::mkOrFilter(
ReflectorClient::TgFilter(tg),
ReflectorClient::TgMonitorFilter(tg))));
broadcastUdpMsg(MsgUdpFlushSamples(),
ReflectorClient::TgFilter(tg));
}
@@ -2450,7 +2452,9 @@ void Reflector::onTrunkTalkerUpdated(uint32_t tg,
broadcastMsg(MsgTalkerStart(tg, new_cs),
ReflectorClient::mkAndFilter(
ge_v2_client_filter,
ReflectorClient::TgFilter(tg)));
ReflectorClient::mkOrFilter(
ReflectorClient::TgFilter(tg),
ReflectorClient::TgMonitorFilter(tg))));
}
// Forward trunk talker events to connected satellites
+40 -4
View File
@@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <random>
#include <cerrno>
#include <cstring>
#include <ctime>
/****************************************************************************
@@ -260,6 +261,17 @@ bool TrunkLink::isOwnedTG(uint32_t tg) const
} /* TrunkLink::isOwnedTG */
bool TrunkLink::isPeerInterestedTG(uint32_t tg) const
{
auto it = m_peer_interested_tgs.find(tg);
if (it == m_peer_interested_tgs.end())
{
return false;
}
return (std::time(nullptr) - it->second) < PEER_INTEREST_TIMEOUT_S;
} /* TrunkLink::isPeerInterestedTG */
Json::Value TrunkLink::statusJson(void) const
{
Json::Value obj(Json::objectValue);
@@ -357,7 +369,8 @@ void TrunkLink::onInboundDisconnected(Async::FramedTcpConnection* con,
void TrunkLink::onLocalTalkerStart(uint32_t tg, const std::string& callsign)
{
if (!isActive() ||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)))
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
!isPeerInterestedTG(tg)))
{
return;
}
@@ -368,7 +381,8 @@ void TrunkLink::onLocalTalkerStart(uint32_t tg, const std::string& callsign)
void TrunkLink::onLocalTalkerStop(uint32_t tg)
{
if (!isActive() ||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)))
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
!isPeerInterestedTG(tg)))
{
return;
}
@@ -385,7 +399,8 @@ void TrunkLink::onLocalTalkerStop(uint32_t tg)
void TrunkLink::onLocalAudio(uint32_t tg, const std::vector<uint8_t>& audio)
{
if (!isActive() ||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)) ||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
!isPeerInterestedTG(tg)) ||
m_yielded_tgs.count(tg))
{
return;
@@ -397,7 +412,8 @@ void TrunkLink::onLocalAudio(uint32_t tg, const std::vector<uint8_t>& audio)
void TrunkLink::onLocalFlush(uint32_t tg)
{
if (!isActive() ||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)))
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
!isPeerInterestedTG(tg)))
{
return;
}
@@ -599,6 +615,7 @@ void TrunkLink::handleMsgTrunkTalkerStart(std::istream& is)
}
m_peer_active_tgs.insert(tg);
m_peer_interested_tgs[tg] = std::time(nullptr);
TGHandler::instance()->setTrunkTalkerForTG(tg, msg.callsign());
} /* TrunkLink::handleMsgTrunkTalkerStart */
@@ -647,6 +664,9 @@ void TrunkLink::handleMsgTrunkAudio(std::istream& is)
return;
}
// Refresh peer interest timestamp on audio to keep alive during long TX
m_peer_interested_tgs[tg] = std::time(nullptr);
// Rebuild a UDP audio message and broadcast to local clients on this TG
MsgUdpAudio udp_msg(msg.audio());
m_reflector->broadcastUdpMsg(udp_msg, ReflectorClient::TgFilter(tg));
@@ -756,6 +776,21 @@ void TrunkLink::heartbeatTick(Async::Timer* t)
}
}
// Prune expired peer interest entries
time_t now = std::time(nullptr);
for (auto it = m_peer_interested_tgs.begin();
it != m_peer_interested_tgs.end(); )
{
if ((now - it->second) >= PEER_INTEREST_TIMEOUT_S)
{
it = m_peer_interested_tgs.erase(it);
}
else
{
++it;
}
}
// Disable timer when both connections are down
if (!m_con.isConnected() && m_inbound_con == nullptr)
{
@@ -790,6 +825,7 @@ void TrunkLink::clearPeerTalkerState(void)
}
m_peer_active_tgs.clear();
m_yielded_tgs.clear();
m_peer_interested_tgs.clear();
} /* TrunkLink::clearPeerTalkerState */
+8
View File
@@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
****************************************************************************/
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sigc++/sigc++.h>
@@ -155,6 +156,12 @@ class TrunkLink : public sigc::trackable
// TGs currently held by this specific trunk peer (for scoped cleanup)
std::set<uint32_t> m_peer_active_tgs;
// 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.
static const time_t PEER_INTEREST_TIMEOUT_S = 600; // 10 minutes
std::map<uint32_t, time_t> m_peer_interested_tgs;
// Per-connection state
bool m_ob_hello_received = false;
unsigned m_ob_hb_tx_cnt = 0;
@@ -170,6 +177,7 @@ class TrunkLink : public sigc::trackable
bool isOutboundReady(void) const;
bool isInboundReady(void) const;
bool isOwnedTG(uint32_t tg) const;
bool isPeerInterestedTG(uint32_t tg) const;
void onConnected(void);
void onDisconnected(Async::TcpConnection* con,