fix(twin): mirror inbound trunk audio across the twin link

When an external PAIRED=1 peer transmits to a twin pair, it picks a
single sticky socket per transmission and sends every frame on it. The
sticky-selected twin's TrunkLink::handleMsgPeerAudio used to broadcast
locally and to satellites but never relayed to the partner twin — so
local clients on the non-sticky twin were deaf to the audio even though
the talker state was mirrored correctly. The satellite-receive path
already had the symmetric forwarder (forwardSatelliteRawAudioToTwin);
the trunk path was just missing it.

Add Reflector::forwardTrunkAudioToTwin and forwardTrunkFlushToTwin,
modelled on the satellite variants, and invoke them from
TrunkLink::handleMsgPeerAudio and handleMsgPeerFlush after the local +
satellite broadcasts. Loop safety: TwinLink::handleMsgPeerAudio does
not re-forward to trunks, so there is no echo back to the originating
peer. Requires the external peer to use PAIRED=1 with both twin
hostnames in a single section — two independent trunk sections would
defeat the source-trunk exclusion at the external owner and cause
duplicates/echo. The docs now flag PAIRED=1 as mandatory for this
topology.

Test: test_twin.py::test_X4_paired_inbound_reaches_both_twins drives a
refa client on TG 26201 and asserts both ref1 and ref2 receive audio
frames and flush. Also rewrite test_01_twin_handshake and
test_05_twin_wiring_no_errors to read /status.twin instead of scraping
a 120s docker-logs window — the previous form flaked when the mesh had
been up long enough for boot-time log lines to scroll off.
This commit is contained in:
Audric committed 2026-05-14 19:37:44 +02:00
1 parent ef42da52de
commit 6a6cfadd95
6 files changed
+215 -35

No files matched your search

+19
View File
@@ -2855,6 +2855,25 @@ void Reflector::forwardSatelliteFlushToTwin(uint32_t tg)
} /* Reflector::forwardSatelliteFlushToTwin */
void Reflector::forwardTrunkAudioToTwin(uint32_t tg,
const std::vector<uint8_t>& audio)
{
if (m_twin_link != nullptr)
{
m_twin_link->onLocalAudio(tg, audio);
}
} /* Reflector::forwardTrunkAudioToTwin */
void Reflector::forwardTrunkFlushToTwin(uint32_t tg)
{
if (m_twin_link != nullptr)
{
m_twin_link->onLocalFlush(tg);
}
} /* Reflector::forwardTrunkFlushToTwin */
void Reflector::forwardAudioToSatellitesExcept(SatelliteLink* except,
uint32_t tg, const std::vector<uint8_t>& audio)
{
+10
View File
@@ -284,6 +284,16 @@ class Reflector : public sigc::trackable
void forwardTrunkTalkerStopToOtherTrunks(const TrunkLink* src,
uint32_t tg);
// Mirror inbound trunk audio/flush across the [TWIN] link. Without this,
// when an external PAIRED peer's sticky socket lands on one twin, only
// that twin's local clients hear the audio — partner-twin clients on the
// same shared LOCAL_PREFIX would be silent. Parallels the satellite
// forwarders just above; loop safety relies on TwinLink::handleMsgPeerAudio
// not re-forwarding to trunks.
void forwardTrunkAudioToTwin(uint32_t tg,
const std::vector<uint8_t>& audio);
void forwardTrunkFlushToTwin(uint32_t tg);
RedisStore* redisStore(void) const { return m_redis; }
MqttPublisher* mqtt(void) const { return m_mqtt; }
+9
View File
@@ -1170,6 +1170,12 @@ void TrunkLink::handleMsgPeerAudio(std::istream& is)
// Forward trunk audio to connected satellites
m_reflector->forwardAudioToSatellitesExcept(nullptr, local_tg, msg.audio());
// Mirror inbound trunk audio to the [TWIN] partner so PAIRED inbound
// (sticky on one twin) still reaches the non-sticky twin's local clients
// and its satellites. TwinLink::handleMsgPeerAudio does not re-forward to
// trunks, so no echo back to the originating peer.
m_reflector->forwardTrunkAudioToTwin(local_tg, msg.audio());
// Prefix-routed fanout (mirrors talker-start): only fan out if we have
// a route. Cluster TGs without a prefix match stay single-hop.
if (m_reflector->shouldRelayInbound(local_tg))
@@ -1212,6 +1218,9 @@ void TrunkLink::handleMsgPeerFlush(std::istream& is)
// Forward trunk flush to connected satellites
m_reflector->forwardFlushToSatellitesExcept(nullptr, local_tg);
// Mirror flush to the [TWIN] partner — pairs with the audio mirror above.
m_reflector->forwardTrunkFlushToTwin(local_tg);
// Prefix-routed fanout (mirrors talker-start): only fan out if we have
// a route. Cluster TGs without a prefix match stay single-hop.
if (m_reflector->shouldRelayInbound(local_tg))