trunk: owner-relay received audio/flush/talker to other trunk peers
Trunks are meant to form a full audio mesh, but the previous code broadcast trunk-received audio only to local clients and satellites — never to other trunk peers. That made three-way conversations impossible whenever the speaker and the intended listener were both non-owners of the TG (e.g. refA and refC on a TG owned by refB). Now, when a TrunkLink receives MsgTrunkTalkerStart/Stop/Audio/Flush for a TG this reflector locally owns, Reflector re-forwards the event to every other trunk peer via the existing onLocal* filters (shared / cluster / peer-interest). Loop prevention: only the owner relays and the source link is excluded from the fanout, so it stays single-hop. isLocalTG(tg) performs longest-prefix-match across m_local_prefixes vs. m_all_prefixes — owner if our prefix wins globally.
This commit is contained in:
1 parent
962e1ffc10
commit
9f4011d3e2
3 files changed
+139
-2
No files matched your search
@@ -2224,7 +2224,7 @@ void Reflector::initTrunkLinks(void)
|
|||||||
// Collect local prefixes for cluster TG validation
|
// Collect local prefixes for cluster TG validation
|
||||||
std::string local_prefix_str;
|
std::string local_prefix_str;
|
||||||
m_cfg->getValue("GLOBAL", "LOCAL_PREFIX", local_prefix_str);
|
m_cfg->getValue("GLOBAL", "LOCAL_PREFIX", local_prefix_str);
|
||||||
std::vector<std::string> all_prefixes;
|
m_local_prefixes.clear();
|
||||||
{
|
{
|
||||||
std::istringstream ss(local_prefix_str);
|
std::istringstream ss(local_prefix_str);
|
||||||
std::string token;
|
std::string token;
|
||||||
@@ -2232,9 +2232,10 @@ void Reflector::initTrunkLinks(void)
|
|||||||
{
|
{
|
||||||
token.erase(0, token.find_first_not_of(" \t"));
|
token.erase(0, token.find_first_not_of(" \t"));
|
||||||
token.erase(token.find_last_not_of(" \t") + 1);
|
token.erase(token.find_last_not_of(" \t") + 1);
|
||||||
if (!token.empty()) all_prefixes.push_back(token);
|
if (!token.empty()) m_local_prefixes.push_back(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::vector<std::string> all_prefixes = m_local_prefixes;
|
||||||
|
|
||||||
// If Redis is configured, load trunk peer definitions from Redis and
|
// If Redis is configured, load trunk peer definitions from Redis and
|
||||||
// synthesize them into m_cfg so the existing trunk initialization
|
// synthesize them into m_cfg so the existing trunk initialization
|
||||||
@@ -2291,6 +2292,9 @@ void Reflector::initTrunkLinks(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache the mesh-wide prefix set for owner-relay decisions.
|
||||||
|
m_all_prefixes = all_prefixes;
|
||||||
|
|
||||||
// Second pass: create trunk links with full prefix knowledge
|
// Second pass: create trunk links with full prefix knowledge
|
||||||
for (const auto& section : trunk_sections)
|
for (const auto& section : trunk_sections)
|
||||||
{
|
{
|
||||||
@@ -2878,6 +2882,80 @@ std::vector<std::string> Reflector::collectAllTrunkPrefixes(void) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Reflector::isLocalTG(uint32_t tg) const
|
||||||
|
{
|
||||||
|
const std::string s = std::to_string(tg);
|
||||||
|
|
||||||
|
size_t best_local_len = 0;
|
||||||
|
for (const auto& prefix : m_local_prefixes)
|
||||||
|
{
|
||||||
|
if (s.size() >= prefix.size() &&
|
||||||
|
s.compare(0, prefix.size(), prefix) == 0 &&
|
||||||
|
prefix.size() > best_local_len)
|
||||||
|
{
|
||||||
|
best_local_len = prefix.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (best_local_len == 0) return false;
|
||||||
|
|
||||||
|
for (const auto& prefix : m_all_prefixes)
|
||||||
|
{
|
||||||
|
if (prefix.size() > best_local_len &&
|
||||||
|
s.size() >= prefix.size() &&
|
||||||
|
s.compare(0, prefix.size(), prefix) == 0)
|
||||||
|
{
|
||||||
|
return false; // a longer (remote) prefix claims this TG
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} /* Reflector::isLocalTG */
|
||||||
|
|
||||||
|
|
||||||
|
void Reflector::forwardTrunkAudioToOtherTrunks(const TrunkLink* src,
|
||||||
|
uint32_t tg,
|
||||||
|
const std::vector<uint8_t>& audio)
|
||||||
|
{
|
||||||
|
for (auto* link : m_trunk_links)
|
||||||
|
{
|
||||||
|
if (link == src) continue;
|
||||||
|
link->onLocalAudio(tg, audio);
|
||||||
|
}
|
||||||
|
} /* Reflector::forwardTrunkAudioToOtherTrunks */
|
||||||
|
|
||||||
|
|
||||||
|
void Reflector::forwardTrunkFlushToOtherTrunks(const TrunkLink* src,
|
||||||
|
uint32_t tg)
|
||||||
|
{
|
||||||
|
for (auto* link : m_trunk_links)
|
||||||
|
{
|
||||||
|
if (link == src) continue;
|
||||||
|
link->onLocalFlush(tg);
|
||||||
|
}
|
||||||
|
} /* Reflector::forwardTrunkFlushToOtherTrunks */
|
||||||
|
|
||||||
|
|
||||||
|
void Reflector::forwardTrunkTalkerStartToOtherTrunks(
|
||||||
|
const TrunkLink* src, uint32_t tg, const std::string& callsign)
|
||||||
|
{
|
||||||
|
for (auto* link : m_trunk_links)
|
||||||
|
{
|
||||||
|
if (link == src) continue;
|
||||||
|
link->onLocalTalkerStart(tg, callsign);
|
||||||
|
}
|
||||||
|
} /* Reflector::forwardTrunkTalkerStartToOtherTrunks */
|
||||||
|
|
||||||
|
|
||||||
|
void Reflector::forwardTrunkTalkerStopToOtherTrunks(const TrunkLink* src,
|
||||||
|
uint32_t tg)
|
||||||
|
{
|
||||||
|
for (auto* link : m_trunk_links)
|
||||||
|
{
|
||||||
|
if (link == src) continue;
|
||||||
|
link->onLocalTalkerStop(tg);
|
||||||
|
}
|
||||||
|
} /* Reflector::forwardTrunkTalkerStopToOtherTrunks */
|
||||||
|
|
||||||
|
|
||||||
bool Reflector::addTrunkLink(const std::string& section)
|
bool Reflector::addTrunkLink(const std::string& section)
|
||||||
{
|
{
|
||||||
if (m_redis == nullptr) {
|
if (m_redis == nullptr) {
|
||||||
@@ -2917,6 +2995,9 @@ bool Reflector::addTrunkLink(const std::string& section)
|
|||||||
|
|
||||||
// Rebroadcast the full prefix set to every link (including the new one).
|
// Rebroadcast the full prefix set to every link (including the new one).
|
||||||
auto all_prefixes = collectAllTrunkPrefixes();
|
auto all_prefixes = collectAllTrunkPrefixes();
|
||||||
|
all_prefixes.insert(all_prefixes.begin(),
|
||||||
|
m_local_prefixes.begin(), m_local_prefixes.end());
|
||||||
|
m_all_prefixes = all_prefixes;
|
||||||
for (auto* l : m_trunk_links) l->setAllPrefixes(all_prefixes);
|
for (auto* l : m_trunk_links) l->setAllPrefixes(all_prefixes);
|
||||||
|
|
||||||
geulog::info("trunk", "Added trunk link: ", section, " (", p.host,
|
geulog::info("trunk", "Added trunk link: ", section, " (", p.host,
|
||||||
@@ -2938,6 +3019,9 @@ bool Reflector::removeTrunkLink(const std::string& section)
|
|||||||
|
|
||||||
// Rebroadcast the remaining prefix set so peers drop the removed one.
|
// Rebroadcast the remaining prefix set so peers drop the removed one.
|
||||||
auto all_prefixes = collectAllTrunkPrefixes();
|
auto all_prefixes = collectAllTrunkPrefixes();
|
||||||
|
all_prefixes.insert(all_prefixes.begin(),
|
||||||
|
m_local_prefixes.begin(), m_local_prefixes.end());
|
||||||
|
m_all_prefixes = all_prefixes;
|
||||||
for (auto* l : m_trunk_links) l->setAllPrefixes(all_prefixes);
|
for (auto* l : m_trunk_links) l->setAllPrefixes(all_prefixes);
|
||||||
|
|
||||||
geulog::info("trunk", "Removed trunk link: ", section);
|
geulog::info("trunk", "Removed trunk link: ", section);
|
||||||
|
|||||||
@@ -246,6 +246,24 @@ class Reflector : public sigc::trackable
|
|||||||
bool isClusterTG(uint32_t tg) const { return m_cluster_tgs.count(tg) > 0; }
|
bool isClusterTG(uint32_t tg) const { return m_cluster_tgs.count(tg) > 0; }
|
||||||
bool isSatelliteMode(void) const { return m_is_satellite; }
|
bool isSatelliteMode(void) const { return m_is_satellite; }
|
||||||
|
|
||||||
|
// True iff this reflector owns the TG (i.e., our local prefix is the
|
||||||
|
// longest matching prefix across all known prefixes in the mesh).
|
||||||
|
// Used to gate owner-relay fanout of trunk-received audio.
|
||||||
|
bool isLocalTG(uint32_t tg) const;
|
||||||
|
|
||||||
|
// Owner-relay fanout: when we receive trunk traffic for a TG we own,
|
||||||
|
// forward to every other trunk peer except `src`. Each peer's TrunkLink
|
||||||
|
// applies its own shared/cluster/interest filter, so links with no
|
||||||
|
// reason to care drop the forward.
|
||||||
|
void forwardTrunkAudioToOtherTrunks(const TrunkLink* src, uint32_t tg,
|
||||||
|
const std::vector<uint8_t>& audio);
|
||||||
|
void forwardTrunkFlushToOtherTrunks(const TrunkLink* src, uint32_t tg);
|
||||||
|
void forwardTrunkTalkerStartToOtherTrunks(const TrunkLink* src,
|
||||||
|
uint32_t tg,
|
||||||
|
const std::string& callsign);
|
||||||
|
void forwardTrunkTalkerStopToOtherTrunks(const TrunkLink* src,
|
||||||
|
uint32_t tg);
|
||||||
|
|
||||||
RedisStore* redisStore(void) const { return m_redis; }
|
RedisStore* redisStore(void) const { return m_redis; }
|
||||||
|
|
||||||
// Callbacks for SatelliteLink to forward satellite events to trunk peers
|
// Callbacks for SatelliteLink to forward satellite events to trunk peers
|
||||||
@@ -337,6 +355,12 @@ class Reflector : public sigc::trackable
|
|||||||
Json::Value m_status;
|
Json::Value m_status;
|
||||||
|
|
||||||
std::vector<TrunkLink*> m_trunk_links;
|
std::vector<TrunkLink*> m_trunk_links;
|
||||||
|
// Prefix bookkeeping for owner-relay decisions. m_local_prefixes holds
|
||||||
|
// prefixes owned by this reflector (from GLOBAL/LOCAL_PREFIX);
|
||||||
|
// m_all_prefixes is local + every peer's REMOTE_PREFIX. Populated in
|
||||||
|
// initTrunkLinks() and refreshed by addTrunkLink/removeTrunkLink.
|
||||||
|
std::vector<std::string> m_local_prefixes;
|
||||||
|
std::vector<std::string> m_all_prefixes;
|
||||||
// Tracks last-seen callsign set per peer_id so we can DEL dropped
|
// Tracks last-seen callsign set per peer_id so we can DEL dropped
|
||||||
// callsigns from Redis when a peer's node list shrinks.
|
// callsigns from Redis when a peer's node list shrinks.
|
||||||
std::map<std::string, std::set<std::string>> m_peer_node_cache;
|
std::map<std::string, std::set<std::string>> m_peer_node_cache;
|
||||||
|
|||||||
@@ -971,6 +971,15 @@ void TrunkLink::handleMsgTrunkTalkerStart(std::istream& is)
|
|||||||
m_peer_interested_tgs[local_tg] = std::time(nullptr);
|
m_peer_interested_tgs[local_tg] = std::time(nullptr);
|
||||||
TGHandler::instance()->setTrunkTalkerForTG(local_tg, msg.callsign());
|
TGHandler::instance()->setTrunkTalkerForTG(local_tg, msg.callsign());
|
||||||
m_reflector->notifyExternalTrunkTalkerStart(local_tg, m_section, msg.callsign());
|
m_reflector->notifyExternalTrunkTalkerStart(local_tg, m_section, msg.callsign());
|
||||||
|
|
||||||
|
// Owner-relay: if we own this TG, propagate the talker-start to every
|
||||||
|
// other interested trunk peer so their local clients and our mesh-wide
|
||||||
|
// audience learn about the remote talker.
|
||||||
|
if (m_reflector->isLocalTG(local_tg))
|
||||||
|
{
|
||||||
|
m_reflector->forwardTrunkTalkerStartToOtherTrunks(this, local_tg,
|
||||||
|
msg.callsign());
|
||||||
|
}
|
||||||
} /* TrunkLink::handleMsgTrunkTalkerStart */
|
} /* TrunkLink::handleMsgTrunkTalkerStart */
|
||||||
|
|
||||||
|
|
||||||
@@ -999,6 +1008,12 @@ void TrunkLink::handleMsgTrunkTalkerStop(std::istream& is)
|
|||||||
m_peer_active_tgs.erase(local_tg);
|
m_peer_active_tgs.erase(local_tg);
|
||||||
TGHandler::instance()->clearTrunkTalkerForTG(local_tg);
|
TGHandler::instance()->clearTrunkTalkerForTG(local_tg);
|
||||||
m_reflector->notifyExternalTrunkTalkerStop(local_tg, m_section);
|
m_reflector->notifyExternalTrunkTalkerStop(local_tg, m_section);
|
||||||
|
|
||||||
|
// Owner-relay: propagate the talker-stop to every other interested peer.
|
||||||
|
if (m_reflector->isLocalTG(local_tg))
|
||||||
|
{
|
||||||
|
m_reflector->forwardTrunkTalkerStopToOtherTrunks(this, local_tg);
|
||||||
|
}
|
||||||
} /* TrunkLink::handleMsgTrunkTalkerStop */
|
} /* TrunkLink::handleMsgTrunkTalkerStop */
|
||||||
|
|
||||||
|
|
||||||
@@ -1046,6 +1061,13 @@ void TrunkLink::handleMsgTrunkAudio(std::istream& is)
|
|||||||
|
|
||||||
// Forward trunk audio to connected satellites
|
// Forward trunk audio to connected satellites
|
||||||
m_reflector->forwardAudioToSatellitesExcept(nullptr, local_tg, msg.audio());
|
m_reflector->forwardAudioToSatellitesExcept(nullptr, local_tg, msg.audio());
|
||||||
|
|
||||||
|
// Owner-relay: when the TG is ours, fan the audio out to every other
|
||||||
|
// trunk peer that has interest (so mesh-wide audience hears the talker).
|
||||||
|
if (m_reflector->isLocalTG(local_tg))
|
||||||
|
{
|
||||||
|
m_reflector->forwardTrunkAudioToOtherTrunks(this, local_tg, msg.audio());
|
||||||
|
}
|
||||||
} /* TrunkLink::handleMsgTrunkAudio */
|
} /* TrunkLink::handleMsgTrunkAudio */
|
||||||
|
|
||||||
|
|
||||||
@@ -1075,6 +1097,13 @@ void TrunkLink::handleMsgTrunkFlush(std::istream& is)
|
|||||||
|
|
||||||
// Forward trunk flush to connected satellites
|
// Forward trunk flush to connected satellites
|
||||||
m_reflector->forwardFlushToSatellitesExcept(nullptr, local_tg);
|
m_reflector->forwardFlushToSatellitesExcept(nullptr, local_tg);
|
||||||
|
|
||||||
|
// Owner-relay: when the TG is ours, fan the flush out to every other
|
||||||
|
// trunk peer so their clients see end-of-stream as well.
|
||||||
|
if (m_reflector->isLocalTG(local_tg))
|
||||||
|
{
|
||||||
|
m_reflector->forwardTrunkFlushToOtherTrunks(this, local_tg);
|
||||||
|
}
|
||||||
} /* TrunkLink::handleMsgTrunkFlush */
|
} /* TrunkLink::handleMsgTrunkFlush */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user