Implement cluster TGs and /config HTTP endpoint
Cluster TGs (BrandMeister-style): talk groups broadcast to all trunk peers regardless of prefix ownership. Configured via CLUSTER_TGS in [GLOBAL]. Routing checks in TrunkLink now accept isSharedTG || isClusterTG for all 8 inbound/outbound handlers. Validated at startup to not overlap with any LOCAL_PREFIX or REMOTE_PREFIX. New GET /config endpoint returns static configuration (local_prefix, cluster_tgs, listen_port, http_port, trunk peers) for dashboard use. Docs: cluster TG sections added to README, DEPLOYMENT_ITALY, and Italian translation. Design doc for satellite reflectors and cluster TGs added.
This commit is contained in:
1 parent
e26b932223
commit
166e57f445
8 files changed
+647
-17
No files matched your search
@@ -390,6 +390,33 @@ bool Reflector::initialize(Async::Config &cfg)
|
||||
|
||||
m_cfg->valueUpdated.connect(sigc::mem_fun(*this, &Reflector::cfgUpdated));
|
||||
|
||||
// Parse CLUSTER_TGS — comma-separated list of TG numbers broadcast to all peers
|
||||
std::string cluster_tgs_str;
|
||||
if (cfg.getValue("GLOBAL", "CLUSTER_TGS", cluster_tgs_str))
|
||||
{
|
||||
std::istringstream ctss(cluster_tgs_str);
|
||||
std::string token;
|
||||
while (std::getline(ctss, token, ','))
|
||||
{
|
||||
token.erase(0, token.find_first_not_of(" \t"));
|
||||
token.erase(token.find_last_not_of(" \t") + 1);
|
||||
if (!token.empty())
|
||||
{
|
||||
uint32_t tg = static_cast<uint32_t>(std::stoul(token));
|
||||
m_cluster_tgs.insert(tg);
|
||||
}
|
||||
}
|
||||
if (!m_cluster_tgs.empty())
|
||||
{
|
||||
std::cout << "Cluster TGs:";
|
||||
for (uint32_t tg : m_cluster_tgs)
|
||||
{
|
||||
std::cout << " " << tg;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
initTrunkLinks();
|
||||
|
||||
return true;
|
||||
@@ -1425,6 +1452,74 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.target == "/config")
|
||||
{
|
||||
Json::Value cfg_json(Json::objectValue);
|
||||
|
||||
// Local prefixes
|
||||
std::string local_prefix_str;
|
||||
m_cfg->getValue("GLOBAL", "LOCAL_PREFIX", local_prefix_str);
|
||||
Json::Value lp_arr(Json::arrayValue);
|
||||
{
|
||||
std::istringstream ss(local_prefix_str);
|
||||
std::string token;
|
||||
while (std::getline(ss, token, ','))
|
||||
{
|
||||
token.erase(0, token.find_first_not_of(" \t"));
|
||||
token.erase(token.find_last_not_of(" \t") + 1);
|
||||
if (!token.empty()) lp_arr.append(token);
|
||||
}
|
||||
}
|
||||
cfg_json["local_prefix"] = lp_arr;
|
||||
|
||||
// Cluster TGs
|
||||
Json::Value cluster_arr(Json::arrayValue);
|
||||
for (uint32_t tg : m_cluster_tgs)
|
||||
{
|
||||
cluster_arr.append(tg);
|
||||
}
|
||||
cfg_json["cluster_tgs"] = cluster_arr;
|
||||
|
||||
// Trunk peers (static config)
|
||||
Json::Value peers(Json::objectValue);
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
Json::Value peer(Json::objectValue);
|
||||
Json::Value link_status = link->statusJson();
|
||||
peer["host"] = link_status["host"];
|
||||
peer["port"] = link_status["port"];
|
||||
peer["remote_prefix"] = link_status["remote_prefix"];
|
||||
peers[link->section()] = peer;
|
||||
}
|
||||
cfg_json["trunks"] = peers;
|
||||
|
||||
// Listen port
|
||||
std::string listen_port("5300");
|
||||
m_cfg->getValue("GLOBAL", "LISTEN_PORT", listen_port);
|
||||
cfg_json["listen_port"] = listen_port;
|
||||
|
||||
// HTTP port
|
||||
std::string http_port;
|
||||
if (m_cfg->getValue("GLOBAL", "HTTP_SRV_PORT", http_port))
|
||||
{
|
||||
cfg_json["http_port"] = http_port;
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
builder["indentation"] = "";
|
||||
Json::StreamWriter* writer = builder.newStreamWriter();
|
||||
writer->write(cfg_json, &os);
|
||||
delete writer;
|
||||
|
||||
res.setContent("application/json", os.str());
|
||||
res.setSendContent(req.method == "GET");
|
||||
res.setCode(200);
|
||||
con->write(res);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.target != "/status")
|
||||
{
|
||||
res.setCode(404);
|
||||
@@ -1442,6 +1537,13 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
||||
}
|
||||
m_status["trunks"] = trunks;
|
||||
|
||||
Json::Value cluster_arr(Json::arrayValue);
|
||||
for (uint32_t tg : m_cluster_tgs)
|
||||
{
|
||||
cluster_arr.append(tg);
|
||||
}
|
||||
m_status["cluster_tgs"] = cluster_arr;
|
||||
|
||||
std::ostringstream os;
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
@@ -1746,12 +1848,42 @@ void Reflector::cfgUpdated(const std::string& section, const std::string& tag)
|
||||
|
||||
void Reflector::initTrunkLinks(void)
|
||||
{
|
||||
// Collect local prefixes for cluster TG validation
|
||||
std::string local_prefix_str;
|
||||
m_cfg->getValue("GLOBAL", "LOCAL_PREFIX", local_prefix_str);
|
||||
std::vector<std::string> all_prefixes;
|
||||
{
|
||||
std::istringstream ss(local_prefix_str);
|
||||
std::string token;
|
||||
while (std::getline(ss, token, ','))
|
||||
{
|
||||
token.erase(0, token.find_first_not_of(" \t"));
|
||||
token.erase(token.find_last_not_of(" \t") + 1);
|
||||
if (!token.empty()) all_prefixes.push_back(token);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& section : m_cfg->listSections())
|
||||
{
|
||||
if (section.substr(0, 6) != "TRUNK_")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Collect remote prefixes for validation
|
||||
std::string remote_prefix_str;
|
||||
m_cfg->getValue(section, "REMOTE_PREFIX", remote_prefix_str);
|
||||
{
|
||||
std::istringstream ss(remote_prefix_str);
|
||||
std::string token;
|
||||
while (std::getline(ss, token, ','))
|
||||
{
|
||||
token.erase(0, token.find_first_not_of(" \t"));
|
||||
token.erase(token.find_last_not_of(" \t") + 1);
|
||||
if (!token.empty()) all_prefixes.push_back(token);
|
||||
}
|
||||
}
|
||||
|
||||
auto* link = new TrunkLink(this, *m_cfg, section);
|
||||
if (link->initialize())
|
||||
{
|
||||
@@ -1764,6 +1896,23 @@ void Reflector::initTrunkLinks(void)
|
||||
delete link;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate cluster TGs don't overlap with any prefix
|
||||
for (uint32_t tg : m_cluster_tgs)
|
||||
{
|
||||
std::string s = std::to_string(tg);
|
||||
for (const auto& prefix : all_prefixes)
|
||||
{
|
||||
if (s.size() >= prefix.size() &&
|
||||
s.compare(0, prefix.size(), prefix) == 0)
|
||||
{
|
||||
std::cerr << "*** WARNING: Cluster TG " << tg
|
||||
<< " conflicts with prefix " << prefix
|
||||
<< " — this TG will be routed as cluster (broadcast to all)"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* Reflector::initTrunkLinks */
|
||||
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <sys/time.h>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
@@ -236,6 +237,8 @@ class Reflector : public sigc::trackable
|
||||
|
||||
Json::Value& clientStatus(const std::string& callsign);
|
||||
|
||||
bool isClusterTG(uint32_t tg) const { return m_cluster_tgs.count(tg) > 0; }
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
@@ -281,6 +284,7 @@ class Reflector : public sigc::trackable
|
||||
Json::Value m_status;
|
||||
|
||||
std::vector<TrunkLink*> m_trunk_links;
|
||||
std::set<uint32_t> m_cluster_tgs;
|
||||
|
||||
Reflector(const Reflector&);
|
||||
Reflector& operator=(const Reflector&);
|
||||
|
||||
@@ -223,12 +223,12 @@ Json::Value TrunkLink::statusJson(void) const
|
||||
for (const auto& p : m_remote_prefix) remote_arr.append(p);
|
||||
obj["remote_prefix"] = remote_arr;
|
||||
|
||||
// active_talkers: all TGs currently held by trunk that match our remote prefix
|
||||
// active_talkers: TGs held by trunk that match remote prefix or are cluster TGs
|
||||
Json::Value talkers(Json::objectValue);
|
||||
const auto& trunk_map = TGHandler::instance()->trunkTalkersSnapshot();
|
||||
for (auto& kv : trunk_map)
|
||||
{
|
||||
if (isSharedTG(kv.first))
|
||||
if (isSharedTG(kv.first) || m_reflector->isClusterTG(kv.first))
|
||||
{
|
||||
talkers[std::to_string(kv.first)] = kv.second;
|
||||
}
|
||||
@@ -241,7 +241,8 @@ Json::Value TrunkLink::statusJson(void) const
|
||||
|
||||
void TrunkLink::onLocalTalkerStart(uint32_t tg, const std::string& callsign)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received || !isSharedTG(tg))
|
||||
if (!m_con.isConnected() || !m_hello_received ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -251,7 +252,8 @@ void TrunkLink::onLocalTalkerStart(uint32_t tg, const std::string& callsign)
|
||||
|
||||
void TrunkLink::onLocalTalkerStop(uint32_t tg)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received || !isSharedTG(tg))
|
||||
if (!m_con.isConnected() || !m_hello_received ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -267,7 +269,8 @@ void TrunkLink::onLocalTalkerStop(uint32_t tg)
|
||||
|
||||
void TrunkLink::onLocalAudio(uint32_t tg, const std::vector<uint8_t>& audio)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received || !isSharedTG(tg) ||
|
||||
if (!m_con.isConnected() || !m_hello_received ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)) ||
|
||||
m_yielded_tgs.count(tg))
|
||||
{
|
||||
return;
|
||||
@@ -278,7 +281,8 @@ void TrunkLink::onLocalAudio(uint32_t tg, const std::vector<uint8_t>& audio)
|
||||
|
||||
void TrunkLink::onLocalFlush(uint32_t tg)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received || !isSharedTG(tg))
|
||||
if (!m_con.isConnected() || !m_hello_received ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -447,7 +451,7 @@ void TrunkLink::handleMsgTrunkTalkerStart(std::istream& is)
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (!isSharedTG(tg))
|
||||
if (!isSharedTG(tg) && !m_reflector->isClusterTG(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -491,7 +495,7 @@ void TrunkLink::handleMsgTrunkTalkerStop(std::istream& is)
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (!isSharedTG(tg))
|
||||
if (!isSharedTG(tg) && !m_reflector->isClusterTG(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -513,7 +517,7 @@ void TrunkLink::handleMsgTrunkAudio(std::istream& is)
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (!isSharedTG(tg) || msg.audio().empty())
|
||||
if ((!isSharedTG(tg) && !m_reflector->isClusterTG(tg)) || msg.audio().empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -541,7 +545,7 @@ void TrunkLink::handleMsgTrunkFlush(std::istream& is)
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (!isSharedTG(tg))
|
||||
if (!isSharedTG(tg) && !m_reflector->isClusterTG(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ LISTEN_PORT=5300
|
||||
#CODECS=OPUS
|
||||
TG_FOR_V1_CLIENTS=999
|
||||
#LOCAL_PREFIX=1
|
||||
#CLUSTER_TGS=222,2221,91
|
||||
#RANDOM_QSY_RANGE=12399:100
|
||||
#HTTP_SRV_PORT=8080
|
||||
COMMAND_PTY=/dev/shm/reflector_ctrl
|
||||
|
||||
Reference in new issue
Block a user