Merge jayReflector additions: per-trunk filters, node-list, PTY mute
Ports DJ1JAY / FM-Funknetz' jayReflector features (https://github.com/dj1jay/jayReflector) into GeuReflector while keeping the in-process MqttPublisher. Per-trunk config (TrunkLink): BLACKLIST_TGS, ALLOW_TGS, TG_MAP (with explicit-route bypass of the prefix routing check), PEER_ID. New helpers TgFilter.h provide exact / "24*" / "10-20" syntax shared across keys. Wire protocol (additive, backward compatible — older peers ignore unknown types): MsgTrunkNodeList (type 121) carries callsign + current_tg + optional lat/lon/QTH; MsgTrunkFilter (type 122) reserved for satellite TG filters. Reflector emits debounced (500 ms) MsgTrunkNodeList to all trunk peers on local client login/logout/TG change. Inbound lists are republished via MQTT under nodes/<peer_id>; the local list under nodes/local. New MQTT_NAME global key inserts a path component so several reflectors can share a TOPIC_PREFIX. PTY commands (Reflector): TRUNK MUTE|UNMUTE <section> <callsign>, TRUNK RELOAD [<section>] re-reads BLACKLIST_TGS/ALLOW_TGS/TG_MAP without restart, TRUNK STATUS [<section>] dumps a one-line summary per link. Mute is applied on the inbound audio path. Tests: 8 new integration tests (19-27) plus a TEST_PEER_FILTER fixture in topology.py. Tests cover PEER_ID hello, BLACKLIST/ALLOW/TG_MAP semantics, PTY MUTE/RELOAD/STATUS via docker exec, MQTT_NAME topic namespacing, and node-list emission. Total now 27 tests. Docs: docs/JAY-additions.md credits DJ1JAY / FM-Funknetz and lists every merged feature with file pointers and the filter-evaluation order. README.md links it. svxreflector.conf.in documents every new key. Bumps SVXREFLECTOR to 1.3.99.13+trunk.
This commit is contained in:
1 parent
6f5138cd11
commit
5708e2d0e8
17 files changed
+1287
-58
No files matched your search
@@ -89,6 +89,16 @@ bool MqttPublisher::initialize(void)
|
||||
m_topic_prefix.pop_back();
|
||||
}
|
||||
|
||||
// Optional MQTT_NAME — appended as a path component so each reflector
|
||||
// publishes under a unique sub-tree (TOPIC_PREFIX/MQTT_NAME/...).
|
||||
string mqtt_name;
|
||||
if (m_cfg.getValue("MQTT", "MQTT_NAME", mqtt_name) && !mqtt_name.empty())
|
||||
{
|
||||
while (!mqtt_name.empty() && mqtt_name.back() == '/') mqtt_name.pop_back();
|
||||
while (!mqtt_name.empty() && mqtt_name.front() == '/') mqtt_name.erase(0, 1);
|
||||
if (!mqtt_name.empty()) m_topic_prefix += "/" + mqtt_name;
|
||||
}
|
||||
|
||||
// Read optional TLS config
|
||||
string tls_str;
|
||||
if (m_cfg.getValue("MQTT", "TLS_ENABLED", tls_str) && tls_str == "1")
|
||||
@@ -283,3 +293,47 @@ void MqttPublisher::publishFullStatus(const Json::Value& status)
|
||||
wb["indentation"] = "";
|
||||
publish("status", Json::writeString(wb, status), true);
|
||||
}
|
||||
|
||||
|
||||
static Json::Value nodeListToJson(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
Json::Value arr(Json::arrayValue);
|
||||
for (const auto& n : nodes)
|
||||
{
|
||||
Json::Value e;
|
||||
e["callsign"] = n.callsign;
|
||||
e["tg"] = n.tg;
|
||||
if (n.lat != 0.0f || n.lon != 0.0f)
|
||||
{
|
||||
e["lat"] = n.lat;
|
||||
e["lon"] = n.lon;
|
||||
}
|
||||
if (!n.qth_name.empty()) e["qth_name"] = n.qth_name;
|
||||
arr.append(e);
|
||||
}
|
||||
Json::Value root;
|
||||
root["nodes"] = arr;
|
||||
root["timestamp"] = (Json::Int64)time(nullptr);
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
void MqttPublisher::publishLocalNodes(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
Json::StreamWriterBuilder wb;
|
||||
wb["indentation"] = "";
|
||||
publish("nodes/local",
|
||||
Json::writeString(wb, nodeListToJson(nodes)), true);
|
||||
}
|
||||
|
||||
|
||||
void MqttPublisher::publishPeerNodes(const std::string& peer_id,
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
Json::StreamWriterBuilder wb;
|
||||
wb["indentation"] = "";
|
||||
publish("nodes/" + peer_id,
|
||||
Json::writeString(wb, nodeListToJson(nodes)), true);
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <json/json.h>
|
||||
#include "ReflectorMsg.h"
|
||||
|
||||
struct mosquitto;
|
||||
|
||||
@@ -38,6 +40,12 @@ class MqttPublisher
|
||||
// Periodic full status
|
||||
void publishFullStatus(const Json::Value& status);
|
||||
|
||||
// Node-list snapshots — published retained
|
||||
void publishLocalNodes(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes);
|
||||
void publishPeerNodes(const std::string& peer_id,
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes);
|
||||
|
||||
private:
|
||||
Async::Config& m_cfg;
|
||||
struct mosquitto* m_mosq = nullptr;
|
||||
|
||||
@@ -245,9 +245,14 @@ Reflector::Reflector(void)
|
||||
m_random_qsy_hi(0), m_random_qsy_tg(0), m_http_server(0), m_cmd_pty(0),
|
||||
m_keys_dir("private/"), m_pending_csrs_dir("pending_csrs/"),
|
||||
m_csrs_dir("csrs/"), m_certs_dir("certs/"), m_pki_dir("pki/"),
|
||||
m_nodelist_timer(500, Async::Timer::TYPE_ONESHOT),
|
||||
m_sat_cleanup_timer(0, Async::Timer::TYPE_ONESHOT),
|
||||
m_mqtt_status_timer(1000, Async::Timer::TYPE_ONESHOT)
|
||||
{
|
||||
m_nodelist_timer.setEnable(false);
|
||||
m_nodelist_timer.expired.connect(
|
||||
[this](Async::Timer*) { sendNodeListToAllPeers(); });
|
||||
|
||||
TGHandler::instance()->talkerUpdated.connect(
|
||||
mem_fun(*this, &Reflector::onTalkerUpdated));
|
||||
TGHandler::instance()->requestAutoQsy.connect(
|
||||
@@ -1051,6 +1056,7 @@ void Reflector::clientDisconnected(Async::FramedTcpConnection *con,
|
||||
{
|
||||
m_mqtt->onClientDisconnected(client->callsign());
|
||||
}
|
||||
scheduleNodeListUpdate();
|
||||
}
|
||||
//Application::app().runTask([=]{ delete client; });
|
||||
delete client;
|
||||
@@ -1949,13 +1955,101 @@ void Reflector::ctrlPtyDataReceived(const void *buf, size_t count)
|
||||
goto write_status;
|
||||
}
|
||||
}
|
||||
else if (cmd == "TRUNK")
|
||||
{
|
||||
std::string subcmd;
|
||||
if (!(ss >> subcmd))
|
||||
{
|
||||
errss << "Invalid TRUNK PTY command. "
|
||||
"Usage: TRUNK MUTE|UNMUTE <section> <callsign> | "
|
||||
"TRUNK RELOAD [<section>] | TRUNK STATUS [<section>]";
|
||||
goto write_status;
|
||||
}
|
||||
std::transform(subcmd.begin(), subcmd.end(), subcmd.begin(), ::toupper);
|
||||
|
||||
auto find_link = [&](const std::string& section) -> TrunkLink* {
|
||||
for (auto* link : m_trunk_links)
|
||||
if (link->section() == section) return link;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
if (subcmd == "MUTE" || subcmd == "UNMUTE")
|
||||
{
|
||||
std::string section, callsign;
|
||||
if (!(ss >> section >> callsign))
|
||||
{
|
||||
errss << "Usage: TRUNK " << subcmd << " <section> <callsign>";
|
||||
goto write_status;
|
||||
}
|
||||
TrunkLink* link = find_link(section);
|
||||
if (link == nullptr)
|
||||
{
|
||||
errss << "Unknown trunk section: " << section;
|
||||
goto write_status;
|
||||
}
|
||||
if (subcmd == "MUTE") link->muteCallsign(callsign);
|
||||
else link->unmuteCallsign(callsign);
|
||||
m_cmd_pty->write(section + ": " + subcmd + " " + callsign + "\n");
|
||||
}
|
||||
else if (subcmd == "RELOAD")
|
||||
{
|
||||
std::string section;
|
||||
ss >> section;
|
||||
if (section.empty())
|
||||
{
|
||||
for (auto* link : m_trunk_links) link->reloadConfig();
|
||||
m_cmd_pty->write("Reloaded all trunk links\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
TrunkLink* link = find_link(section);
|
||||
if (link == nullptr)
|
||||
{
|
||||
errss << "Unknown trunk section: " << section;
|
||||
goto write_status;
|
||||
}
|
||||
link->reloadConfig();
|
||||
m_cmd_pty->write(section + ": reloaded\n");
|
||||
}
|
||||
}
|
||||
else if (subcmd == "STATUS")
|
||||
{
|
||||
std::string section;
|
||||
ss >> section;
|
||||
if (section.empty())
|
||||
{
|
||||
for (auto* link : m_trunk_links)
|
||||
m_cmd_pty->write(link->statusLine() + "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
TrunkLink* link = find_link(section);
|
||||
if (link == nullptr)
|
||||
{
|
||||
errss << "Unknown trunk section: " << section;
|
||||
goto write_status;
|
||||
}
|
||||
m_cmd_pty->write(link->statusLine() + "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errss << "Invalid TRUNK subcommand '" << subcmd << "'. "
|
||||
"Usage: TRUNK MUTE|UNMUTE <section> <callsign> | "
|
||||
"TRUNK RELOAD [<section>] | TRUNK STATUS [<section>]";
|
||||
goto write_status;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errss << "Valid commands are: CFG, NODE, CA\n"
|
||||
errss << "Valid commands are: CFG, NODE, CA, TRUNK\n"
|
||||
<< "Usage:\n"
|
||||
<< "CFG <section> <tag> <value>\n"
|
||||
<< "NODE BLOCK <callsign> <blocktime seconds>\n"
|
||||
<< "CA LS|LSC|LSP|SIGN <callsign>|RM <callsign>\n"
|
||||
<< "TRUNK MUTE|UNMUTE <section> <callsign>\n"
|
||||
<< "TRUNK RELOAD [<section>]\n"
|
||||
<< "TRUNK STATUS [<section>]\n"
|
||||
<< "\nEmpty CFG lists all configuration";
|
||||
}
|
||||
|
||||
@@ -2603,22 +2697,70 @@ void Reflector::onClientAuthenticated(const std::string& callsign,
|
||||
{
|
||||
m_mqtt->onClientConnected(callsign, tg, ip);
|
||||
}
|
||||
scheduleNodeListUpdate();
|
||||
} /* Reflector::onClientAuthenticated */
|
||||
|
||||
|
||||
void Reflector::onTrunkStateChanged(const std::string& section,
|
||||
const std::string& direction, bool up,
|
||||
const std::string& host, uint16_t port)
|
||||
void Reflector::scheduleNodeListUpdate(void)
|
||||
{
|
||||
// Debounce — multiple rapid login/TG-change events coalesce into one send
|
||||
m_nodelist_timer.setEnable(false);
|
||||
m_nodelist_timer.setTimeout(500);
|
||||
m_nodelist_timer.setEnable(true);
|
||||
} /* Reflector::scheduleNodeListUpdate */
|
||||
|
||||
|
||||
void Reflector::sendNodeListToAllPeers(void)
|
||||
{
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> nodes;
|
||||
for (const auto& kv : m_client_con_map)
|
||||
{
|
||||
ReflectorClient* c = kv.second;
|
||||
if (c->callsign().empty()) continue;
|
||||
MsgTrunkNodeList::NodeEntry e;
|
||||
e.callsign = c->callsign();
|
||||
e.tg = c->currentTG();
|
||||
nodes.push_back(e);
|
||||
}
|
||||
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->sendNodeList(nodes);
|
||||
}
|
||||
|
||||
if (m_mqtt != nullptr)
|
||||
{
|
||||
m_mqtt->publishLocalNodes(nodes);
|
||||
}
|
||||
} /* Reflector::sendNodeListToAllPeers */
|
||||
|
||||
|
||||
void Reflector::onPeerNodeList(const std::string& peer_id,
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
if (m_mqtt != nullptr)
|
||||
{
|
||||
m_mqtt->publishPeerNodes(peer_id, nodes);
|
||||
}
|
||||
} /* Reflector::onPeerNodeList */
|
||||
|
||||
|
||||
void Reflector::onTrunkStateChanged(const std::string& section,
|
||||
const std::string& peer_id,
|
||||
const std::string& direction, bool up,
|
||||
const std::string& host, uint16_t port)
|
||||
{
|
||||
(void)section; // reserved for local logging; MQTT uses peer_id
|
||||
if (m_mqtt != nullptr)
|
||||
{
|
||||
const std::string& topic_id = peer_id.empty() ? section : peer_id;
|
||||
if (up)
|
||||
{
|
||||
m_mqtt->onTrunkUp(section, direction, host, port);
|
||||
m_mqtt->onTrunkUp(topic_id, direction, host, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mqtt->onTrunkDown(section, direction);
|
||||
m_mqtt->onTrunkDown(topic_id, direction);
|
||||
}
|
||||
}
|
||||
} /* Reflector::onTrunkStateChanged */
|
||||
|
||||
@@ -65,6 +65,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "ProtoVer.h"
|
||||
#include "ReflectorClient.h"
|
||||
#include "TrunkLink.h"
|
||||
#include "ReflectorMsg.h"
|
||||
#include "SatelliteLink.h"
|
||||
#include "SatelliteClient.h"
|
||||
#include "MqttPublisher.h"
|
||||
@@ -258,10 +259,18 @@ class Reflector : public sigc::trackable
|
||||
void onClientAuthenticated(const std::string& callsign, uint32_t tg,
|
||||
const std::string& ip);
|
||||
void onTrunkStateChanged(const std::string& section,
|
||||
const std::string& peer_id,
|
||||
const std::string& direction, bool up,
|
||||
const std::string& host = "",
|
||||
uint16_t port = 0);
|
||||
|
||||
// Triggered when a local client logs in/out or changes TG. Schedules
|
||||
// a debounced node-list emission to all trunk peers and to MQTT.
|
||||
void scheduleNodeListUpdate(void);
|
||||
// Called by TrunkLink when a peer sends us its node list.
|
||||
void onPeerNodeList(const std::string& peer_id,
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
@@ -309,6 +318,7 @@ class Reflector : public sigc::trackable
|
||||
std::vector<TrunkLink*> m_trunk_links;
|
||||
std::set<uint32_t> m_cluster_tgs;
|
||||
bool m_trunk_debug = false;
|
||||
Async::Timer m_nodelist_timer;
|
||||
static const size_t TRUNK_MAX_PENDING_CONS = 5;
|
||||
|
||||
FramedTcpServer* m_trunk_srv = nullptr;
|
||||
@@ -367,6 +377,7 @@ class Reflector : public sigc::trackable
|
||||
Async::FramedTcpConnection::DisconnectReason reason);
|
||||
void onSatelliteLinkFailed(SatelliteLink* link);
|
||||
void processSatelliteCleanup(Async::Timer* t);
|
||||
void sendNodeListToAllPeers(void);
|
||||
bool loadCertificateFiles(void);
|
||||
bool loadServerCertificateFiles(void);
|
||||
bool generateKeyFile(Async::SslKeypair& pkey, const std::string& keyfile);
|
||||
|
||||
@@ -1444,6 +1444,7 @@ void ReflectorClient::setTg(uint32_t tg)
|
||||
}
|
||||
|
||||
m_current_tg = tg;
|
||||
if (m_reflector != nullptr) m_reflector->scheduleNodeListUpdate();
|
||||
}
|
||||
|
||||
if (m_status != nullptr)
|
||||
|
||||
@@ -1821,6 +1821,93 @@ class MsgUdpAudio : public ReflectorUdpMsgBase<101>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
@brief Trunk node list message (jayReflector extension, type 121)
|
||||
|
||||
Sent by a reflector to its trunk peer whenever its local client list changes
|
||||
(login, logout, TG change). The receiving peer can publish it via its own
|
||||
MQTT publisher. Older peers that don't know type 121 ignore it — fully
|
||||
backward compatible.
|
||||
|
||||
Each entry: callsign, current TG, optional lat/lon/QTH name.
|
||||
*/
|
||||
class MsgTrunkNodeList : public ReflectorMsgBase<121>
|
||||
{
|
||||
public:
|
||||
struct NodeEntry
|
||||
{
|
||||
std::string callsign;
|
||||
uint32_t tg = 0;
|
||||
float lat = 0.0f;
|
||||
float lon = 0.0f;
|
||||
std::string qth_name;
|
||||
};
|
||||
|
||||
MsgTrunkNodeList(void) {}
|
||||
explicit MsgTrunkNodeList(const std::vector<NodeEntry>& nodes)
|
||||
{
|
||||
for (const auto& n : nodes)
|
||||
{
|
||||
m_callsigns.push_back(n.callsign);
|
||||
m_tgs.push_back(n.tg);
|
||||
m_lats.push_back(n.lat);
|
||||
m_lons.push_back(n.lon);
|
||||
m_qth_names.push_back(n.qth_name);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<NodeEntry> nodes(void) const
|
||||
{
|
||||
std::vector<NodeEntry> result;
|
||||
size_t sz = std::min(m_callsigns.size(), m_tgs.size());
|
||||
for (size_t i = 0; i < sz; ++i)
|
||||
{
|
||||
NodeEntry e;
|
||||
e.callsign = m_callsigns[i];
|
||||
e.tg = m_tgs[i];
|
||||
e.lat = (i < m_lats.size()) ? m_lats[i] : 0.0f;
|
||||
e.lon = (i < m_lons.size()) ? m_lons[i] : 0.0f;
|
||||
e.qth_name = (i < m_qth_names.size()) ? m_qth_names[i] : "";
|
||||
result.push_back(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ASYNC_MSG_MEMBERS(m_callsigns, m_tgs, m_lats, m_lons, m_qth_names)
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_callsigns;
|
||||
std::vector<uint32_t> m_tgs;
|
||||
std::vector<float> m_lats;
|
||||
std::vector<float> m_lons;
|
||||
std::vector<std::string> m_qth_names;
|
||||
}; /* MsgTrunkNodeList */
|
||||
|
||||
|
||||
/**
|
||||
@brief Trunk filter advertisement (jayReflector extension, type 122)
|
||||
|
||||
Optional message sent (typically by a satellite after Hello) to tell the
|
||||
parent which TGs it wants to receive. Filter syntax matches TgFilter
|
||||
(exact / "24*" prefix / "10-20" range, comma-separated). Older peers
|
||||
silently ignore unknown message types.
|
||||
*/
|
||||
class MsgTrunkFilter : public ReflectorMsgBase<122>
|
||||
{
|
||||
public:
|
||||
MsgTrunkFilter(void) {}
|
||||
explicit MsgTrunkFilter(const std::string& filter)
|
||||
: m_filter(filter) {}
|
||||
|
||||
const std::string& filter(void) const { return m_filter; }
|
||||
|
||||
ASYNC_MSG_MEMBERS(m_filter)
|
||||
|
||||
private:
|
||||
std::string m_filter;
|
||||
}; /* MsgTrunkFilter */
|
||||
|
||||
|
||||
#endif /* REFLECTOR_MSG_INCLUDED */
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* @file TgFilter.h
|
||||
* @brief Flexible TG filter: exact, prefix (*), range (-)
|
||||
* @author DJ1JAY / FM-Funknetz
|
||||
*
|
||||
* Syntax (comma-separated):
|
||||
* 24* — prefix match: all TGs starting with "24"
|
||||
* 2427-2438 — range: TG 2427..2438 inclusive
|
||||
* 26200 — exact match: only TG 26200
|
||||
*
|
||||
* Empty filter = match all.
|
||||
*
|
||||
* Example:
|
||||
* TgFilter f = TgFilter::parse("24*,2427-2438,26200");
|
||||
* f.matches(24) → true
|
||||
* f.matches(2430) → true
|
||||
* f.matches(26200) → true
|
||||
* f.matches(26201) → false
|
||||
*/
|
||||
|
||||
#ifndef TGFILTER_H
|
||||
#define TGFILTER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
struct TgFilter
|
||||
{
|
||||
struct Entry
|
||||
{
|
||||
enum Type { EXACT, PREFIX, RANGE } type;
|
||||
uint32_t value = 0;
|
||||
uint32_t range_end = 0;
|
||||
std::string prefix;
|
||||
};
|
||||
|
||||
std::vector<Entry> entries;
|
||||
bool empty(void) const { return entries.empty(); }
|
||||
|
||||
static TgFilter parse(const std::string& s)
|
||||
{
|
||||
TgFilter f;
|
||||
std::istringstream ss(s);
|
||||
std::string tok;
|
||||
while (std::getline(ss, tok, ','))
|
||||
{
|
||||
tok.erase(0, tok.find_first_not_of(" \t"));
|
||||
tok.erase(tok.find_last_not_of(" \t") + 1);
|
||||
if (tok.empty()) continue;
|
||||
|
||||
Entry e;
|
||||
if (!tok.empty() && tok.back() == '*')
|
||||
{
|
||||
e.type = Entry::PREFIX;
|
||||
e.prefix = tok.substr(0, tok.size() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto dash = tok.find('-');
|
||||
if (dash != std::string::npos)
|
||||
{
|
||||
try {
|
||||
e.type = Entry::RANGE;
|
||||
e.value = std::stoul(tok.substr(0, dash));
|
||||
e.range_end = std::stoul(tok.substr(dash + 1));
|
||||
} catch (...) { continue; }
|
||||
}
|
||||
else
|
||||
{
|
||||
try {
|
||||
e.type = Entry::EXACT;
|
||||
e.value = std::stoul(tok);
|
||||
} catch (...) { continue; }
|
||||
}
|
||||
}
|
||||
f.entries.push_back(e);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
bool matches(uint32_t tg) const
|
||||
{
|
||||
if (entries.empty()) return true;
|
||||
const std::string s = std::to_string(tg);
|
||||
for (const auto& e : entries)
|
||||
{
|
||||
switch (e.type)
|
||||
{
|
||||
case Entry::EXACT:
|
||||
if (tg == e.value) return true;
|
||||
break;
|
||||
case Entry::PREFIX:
|
||||
if (s.size() >= e.prefix.size() &&
|
||||
s.compare(0, e.prefix.size(), e.prefix) == 0)
|
||||
return true;
|
||||
break;
|
||||
case Entry::RANGE:
|
||||
if (tg >= e.value && tg <= e.range_end) return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string toString(void) const
|
||||
{
|
||||
std::string r;
|
||||
for (const auto& e : entries)
|
||||
{
|
||||
if (!r.empty()) r += ',';
|
||||
switch (e.type)
|
||||
{
|
||||
case Entry::EXACT: r += std::to_string(e.value); break;
|
||||
case Entry::PREFIX: r += e.prefix + "*"; break;
|
||||
case Entry::RANGE: r += std::to_string(e.value) + "-"
|
||||
+ std::to_string(e.range_end); break;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* TGFILTER_H */
|
||||
@@ -191,10 +191,69 @@ bool TrunkLink::initialize(void)
|
||||
m_debug = (debug_str == "1" || debug_str == "true" || debug_str == "yes");
|
||||
}
|
||||
|
||||
// PEER_ID — name we advertise in our hello (defaults to section name).
|
||||
// Used by the receiving peer as the MQTT topic component for this link.
|
||||
if (!m_cfg.getValue(m_section, "PEER_ID", m_peer_id_config)
|
||||
|| m_peer_id_config.empty())
|
||||
{
|
||||
m_peer_id_config = m_section;
|
||||
}
|
||||
|
||||
// BLACKLIST_TGS — flexible filter (exact, prefix "24*", range "10-20")
|
||||
std::string blacklist_str;
|
||||
if (m_cfg.getValue(m_section, "BLACKLIST_TGS", blacklist_str)
|
||||
&& !blacklist_str.empty())
|
||||
{
|
||||
m_blacklist_filter = TgFilter::parse(blacklist_str);
|
||||
if (!m_blacklist_filter.empty())
|
||||
cout << m_section << ": Blacklisted TGs: "
|
||||
<< m_blacklist_filter.toString() << endl;
|
||||
}
|
||||
|
||||
// ALLOW_TGS — flexible whitelist (empty = allow all)
|
||||
std::string allow_str;
|
||||
if (m_cfg.getValue(m_section, "ALLOW_TGS", allow_str) && !allow_str.empty())
|
||||
{
|
||||
m_allow_filter = TgFilter::parse(allow_str);
|
||||
if (!m_allow_filter.empty())
|
||||
cout << m_section << ": Allowed TGs: "
|
||||
<< m_allow_filter.toString() << endl;
|
||||
}
|
||||
|
||||
// TG_MAP — bidirectional TG remap, syntax "peer:local,peer2:local2"
|
||||
std::string tgmap_str;
|
||||
if (m_cfg.getValue(m_section, "TG_MAP", tgmap_str) && !tgmap_str.empty())
|
||||
{
|
||||
std::istringstream ms(tgmap_str);
|
||||
std::string pair;
|
||||
while (std::getline(ms, pair, ','))
|
||||
{
|
||||
auto colon = pair.find(':');
|
||||
if (colon == std::string::npos) continue;
|
||||
try {
|
||||
uint32_t peer_tg = std::stoul(pair.substr(0, colon));
|
||||
uint32_t local_tg = std::stoul(pair.substr(colon + 1));
|
||||
m_tg_map_in[peer_tg] = local_tg;
|
||||
m_tg_map_out[local_tg] = peer_tg;
|
||||
} catch (...) { /* skip malformed */ }
|
||||
}
|
||||
if (!m_tg_map_in.empty())
|
||||
{
|
||||
cout << m_section << ": TG mappings (peer<->local):";
|
||||
for (const auto& kv : m_tg_map_in)
|
||||
cout << " " << kv.first << "<->" << kv.second;
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << m_section << ": Trunk to " << m_peer_host << ":" << m_peer_port
|
||||
<< " local_prefix=" << joinPrefixes(m_local_prefix)
|
||||
<< " remote_prefix=" << joinPrefixes(m_remote_prefix)
|
||||
<< (m_debug ? " [debug on]" : "") << endl;
|
||||
<< (m_debug ? " [debug on]" : "")
|
||||
<< (m_blacklist_filter.empty() ? "" : " [blacklist]")
|
||||
<< (m_allow_filter.empty() ? "" : " [whitelist]")
|
||||
<< (m_tg_map_in.empty() ? "" : " [tg_map]")
|
||||
<< endl;
|
||||
|
||||
m_con.addStaticSRVRecord(0, 0, 0, m_peer_port, m_peer_host);
|
||||
m_con.setReconnectMinTime(2000);
|
||||
@@ -282,6 +341,18 @@ bool TrunkLink::isPeerInterestedTG(uint32_t tg) const
|
||||
} /* TrunkLink::isPeerInterestedTG */
|
||||
|
||||
|
||||
bool TrunkLink::isBlacklisted(uint32_t tg) const
|
||||
{
|
||||
return !m_blacklist_filter.empty() && m_blacklist_filter.matches(tg);
|
||||
} /* TrunkLink::isBlacklisted */
|
||||
|
||||
|
||||
bool TrunkLink::isAllowed(uint32_t tg) const
|
||||
{
|
||||
return m_allow_filter.empty() || m_allow_filter.matches(tg);
|
||||
} /* TrunkLink::isAllowed */
|
||||
|
||||
|
||||
Json::Value TrunkLink::statusJson(void) const
|
||||
{
|
||||
Json::Value obj(Json::objectValue);
|
||||
@@ -350,10 +421,11 @@ void TrunkLink::acceptInboundConnection(Async::FramedTcpConnection* con,
|
||||
con->frameReceived.connect(
|
||||
mem_fun(*this, &TrunkLink::onFrameReceived));
|
||||
|
||||
m_peer_id_received = hello.id();
|
||||
cout << m_section << ": Accepted inbound from " << con->remoteHost()
|
||||
<< ":" << con->remotePort() << " peer='" << hello.id()
|
||||
<< "' priority=" << m_peer_priority << endl;
|
||||
m_reflector->onTrunkStateChanged(m_section, "inbound", true,
|
||||
m_reflector->onTrunkStateChanged(m_section, peerId(), "inbound", true,
|
||||
con->remoteHost().toString(),
|
||||
con->remotePort());
|
||||
|
||||
@@ -366,7 +438,8 @@ void TrunkLink::acceptInboundConnection(Async::FramedTcpConnection* con,
|
||||
}
|
||||
|
||||
// Send our hello back on the inbound connection
|
||||
sendMsgOnInbound(MsgTrunkHello(m_section, joinPrefixes(m_local_prefix),
|
||||
sendMsgOnInbound(MsgTrunkHello(m_peer_id_config,
|
||||
joinPrefixes(m_local_prefix),
|
||||
m_priority, m_secret));
|
||||
} /* TrunkLink::acceptInboundConnection */
|
||||
|
||||
@@ -387,7 +460,7 @@ void TrunkLink::onInboundDisconnected(Async::FramedTcpConnection* con,
|
||||
}
|
||||
|
||||
cout << m_section << ": Inbound trunk connection lost" << endl;
|
||||
m_reflector->onTrunkStateChanged(m_section, "inbound", false);
|
||||
m_reflector->onTrunkStateChanged(m_section, peerId(), "inbound", false);
|
||||
|
||||
if (m_debug)
|
||||
{
|
||||
@@ -416,21 +489,25 @@ void TrunkLink::onInboundDisconnected(Async::FramedTcpConnection* con,
|
||||
|
||||
void TrunkLink::onLocalTalkerStart(uint32_t tg, const std::string& callsign)
|
||||
{
|
||||
if (!isActive() ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg)))
|
||||
if (!isActive() || isBlacklisted(tg) || !isAllowed(tg)) return;
|
||||
bool mapped = m_tg_map_out.count(tg) > 0;
|
||||
if (!mapped &&
|
||||
!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
sendMsg(MsgTrunkTalkerStart(tg, callsign));
|
||||
sendMsg(MsgTrunkTalkerStart(mapTgOut(tg), callsign));
|
||||
} /* TrunkLink::onLocalTalkerStart */
|
||||
|
||||
|
||||
void TrunkLink::onLocalTalkerStop(uint32_t tg)
|
||||
{
|
||||
if (!isActive() ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg)))
|
||||
if (!isActive() || isBlacklisted(tg) || !isAllowed(tg)) return;
|
||||
bool mapped = m_tg_map_out.count(tg) > 0;
|
||||
if (!mapped &&
|
||||
!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -440,32 +517,39 @@ void TrunkLink::onLocalTalkerStop(uint32_t tg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
sendMsg(MsgTrunkTalkerStop(tg));
|
||||
sendMsg(MsgTrunkTalkerStop(mapTgOut(tg)));
|
||||
} /* TrunkLink::onLocalTalkerStop */
|
||||
|
||||
|
||||
void TrunkLink::onLocalAudio(uint32_t tg, const std::vector<uint8_t>& audio)
|
||||
{
|
||||
if (!isActive() ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg)) ||
|
||||
m_yielded_tgs.count(tg))
|
||||
if (!isActive() || isBlacklisted(tg) || !isAllowed(tg)
|
||||
|| m_yielded_tgs.count(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
sendMsg(MsgTrunkAudio(tg, audio));
|
||||
bool mapped = m_tg_map_out.count(tg) > 0;
|
||||
if (!mapped &&
|
||||
!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
sendMsg(MsgTrunkAudio(mapTgOut(tg), audio));
|
||||
} /* TrunkLink::onLocalAudio */
|
||||
|
||||
|
||||
void TrunkLink::onLocalFlush(uint32_t tg)
|
||||
{
|
||||
if (!isActive() ||
|
||||
(!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg)))
|
||||
if (!isActive() || isBlacklisted(tg) || !isAllowed(tg)) return;
|
||||
bool mapped = m_tg_map_out.count(tg) > 0;
|
||||
if (!mapped &&
|
||||
!isSharedTG(tg) && !m_reflector->isClusterTG(tg) &&
|
||||
!isPeerInterestedTG(tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
sendMsg(MsgTrunkFlush(tg));
|
||||
sendMsg(MsgTrunkFlush(mapTgOut(tg)));
|
||||
} /* TrunkLink::onLocalFlush */
|
||||
|
||||
|
||||
@@ -479,7 +563,7 @@ void TrunkLink::onConnected(void)
|
||||
{
|
||||
cout << m_section << ": Outbound connected to " << m_con.remoteHost()
|
||||
<< ":" << m_con.remotePort() << endl;
|
||||
m_reflector->onTrunkStateChanged(m_section, "outbound", true,
|
||||
m_reflector->onTrunkStateChanged(m_section, peerId(), "outbound", true,
|
||||
m_con.remoteHost().toString(),
|
||||
m_con.remotePort());
|
||||
|
||||
@@ -495,7 +579,8 @@ void TrunkLink::onConnected(void)
|
||||
m_ob_hb_rx_cnt = HEARTBEAT_RX_CNT_RESET;
|
||||
m_heartbeat_timer.setEnable(true);
|
||||
|
||||
sendMsgOnOutbound(MsgTrunkHello(m_section, joinPrefixes(m_local_prefix),
|
||||
sendMsgOnOutbound(MsgTrunkHello(m_peer_id_config,
|
||||
joinPrefixes(m_local_prefix),
|
||||
m_priority, m_secret));
|
||||
} /* TrunkLink::onConnected */
|
||||
|
||||
@@ -505,7 +590,7 @@ void TrunkLink::onDisconnected(TcpConnection* con,
|
||||
{
|
||||
cout << m_section << ": Outbound disconnected: "
|
||||
<< TcpConnection::disconnectReasonStr(reason) << endl;
|
||||
m_reflector->onTrunkStateChanged(m_section, "outbound", false);
|
||||
m_reflector->onTrunkStateChanged(m_section, peerId(), "outbound", false);
|
||||
|
||||
if (m_debug)
|
||||
{
|
||||
@@ -612,6 +697,9 @@ void TrunkLink::onFrameReceived(FramedTcpConnection* con,
|
||||
case MsgTrunkFlush::TYPE:
|
||||
handleMsgTrunkFlush(ss);
|
||||
break;
|
||||
case MsgTrunkNodeList::TYPE:
|
||||
handleMsgTrunkNodeList(ss);
|
||||
break;
|
||||
default:
|
||||
cerr << "*** WARNING[" << m_section
|
||||
<< "]: Unknown trunk message type=" << header.type() << endl;
|
||||
@@ -669,6 +757,7 @@ void TrunkLink::handleMsgTrunkHello(std::istream& is, bool is_inbound)
|
||||
}
|
||||
|
||||
m_peer_priority = msg.priority();
|
||||
m_peer_id_received = msg.id();
|
||||
m_ob_hello_received = true;
|
||||
|
||||
cout << m_section << ": Trunk hello from peer '" << msg.id()
|
||||
@@ -696,38 +785,44 @@ void TrunkLink::handleMsgTrunkTalkerStart(std::istream& is)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (!isOwnedTG(tg) && !m_reflector->isClusterTG(tg))
|
||||
uint32_t wire_tg = msg.tg();
|
||||
uint32_t local_tg = mapTgIn(wire_tg);
|
||||
if (isBlacklisted(wire_tg) || isBlacklisted(local_tg) || !isAllowed(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool mapped = m_tg_map_in.count(wire_tg) > 0;
|
||||
if (!mapped && !isOwnedTG(wire_tg) && !m_reflector->isClusterTG(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Tie-break: if we already have a local talker on this TG, decide who wins.
|
||||
// Lower priority value wins. If equal (shouldn't happen), local wins.
|
||||
ReflectorClient* local_talker = TGHandler::instance()->talkerForTG(tg);
|
||||
ReflectorClient* local_talker = TGHandler::instance()->talkerForTG(local_tg);
|
||||
if (local_talker != nullptr)
|
||||
{
|
||||
if (m_priority <= m_peer_priority)
|
||||
{
|
||||
// We win — ignore peer's claim
|
||||
cout << m_section << ": TG #" << tg
|
||||
cout << m_section << ": TG #" << local_tg
|
||||
<< " conflict — local wins (our priority=" << m_priority
|
||||
<< " <= peer=" << m_peer_priority << ")" << endl;
|
||||
return;
|
||||
}
|
||||
// We defer — clear local talker and accept remote
|
||||
cout << m_section << ": TG #" << tg
|
||||
cout << m_section << ": TG #" << local_tg
|
||||
<< " conflict — deferring to peer (our priority=" << m_priority
|
||||
<< " > peer=" << m_peer_priority << ")" << endl;
|
||||
m_yielded_tgs.insert(tg);
|
||||
TGHandler::instance()->setTalkerForTG(tg, nullptr);
|
||||
m_yielded_tgs.insert(local_tg);
|
||||
TGHandler::instance()->setTalkerForTG(local_tg, nullptr);
|
||||
// onTalkerUpdated will fire; Reflector must not re-send TrunkTalkerStart
|
||||
// for this TG since it's in m_yielded_tgs (checked in Reflector.cpp)
|
||||
}
|
||||
|
||||
m_peer_active_tgs.insert(tg);
|
||||
m_peer_interested_tgs[tg] = std::time(nullptr);
|
||||
TGHandler::instance()->setTrunkTalkerForTG(tg, msg.callsign());
|
||||
m_peer_active_tgs.insert(local_tg);
|
||||
m_peer_interested_tgs[local_tg] = std::time(nullptr);
|
||||
TGHandler::instance()->setTrunkTalkerForTG(local_tg, msg.callsign());
|
||||
} /* TrunkLink::handleMsgTrunkTalkerStart */
|
||||
|
||||
|
||||
@@ -741,15 +836,21 @@ void TrunkLink::handleMsgTrunkTalkerStop(std::istream& is)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (!isOwnedTG(tg) && !m_reflector->isClusterTG(tg))
|
||||
uint32_t wire_tg = msg.tg();
|
||||
uint32_t local_tg = mapTgIn(wire_tg);
|
||||
if (isBlacklisted(wire_tg) || isBlacklisted(local_tg) || !isAllowed(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool mapped = m_tg_map_in.count(wire_tg) > 0;
|
||||
if (!mapped && !isOwnedTG(wire_tg) && !m_reflector->isClusterTG(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_yielded_tgs.erase(tg);
|
||||
m_peer_active_tgs.erase(tg);
|
||||
TGHandler::instance()->clearTrunkTalkerForTG(tg);
|
||||
m_yielded_tgs.erase(local_tg);
|
||||
m_peer_active_tgs.erase(local_tg);
|
||||
TGHandler::instance()->clearTrunkTalkerForTG(local_tg);
|
||||
} /* TrunkLink::handleMsgTrunkTalkerStop */
|
||||
|
||||
|
||||
@@ -763,27 +864,41 @@ void TrunkLink::handleMsgTrunkAudio(std::istream& is)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if ((!isOwnedTG(tg) && !m_reflector->isClusterTG(tg)) || msg.audio().empty())
|
||||
uint32_t wire_tg = msg.tg();
|
||||
uint32_t local_tg = mapTgIn(wire_tg);
|
||||
if (msg.audio().empty()) return;
|
||||
if (isBlacklisted(wire_tg) || isBlacklisted(local_tg) || !isAllowed(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool mapped = m_tg_map_in.count(wire_tg) > 0;
|
||||
if (!mapped && !isOwnedTG(wire_tg) && !m_reflector->isClusterTG(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Only forward audio if this peer has claimed the TG via TalkerStart
|
||||
if (m_peer_active_tgs.find(tg) == m_peer_active_tgs.end())
|
||||
if (m_peer_active_tgs.find(local_tg) == m_peer_active_tgs.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// PTY-driven mute: drop audio if the current peer talker is muted
|
||||
std::string cs = TGHandler::instance()->trunkTalkerForTG(local_tg);
|
||||
if (!cs.empty() && isCallsignMuted(cs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Refresh peer interest timestamp on audio to keep alive during long TX
|
||||
m_peer_interested_tgs[tg] = std::time(nullptr);
|
||||
m_peer_interested_tgs[local_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));
|
||||
m_reflector->broadcastUdpMsg(udp_msg, ReflectorClient::TgFilter(local_tg));
|
||||
|
||||
// Forward trunk audio to connected satellites
|
||||
m_reflector->forwardAudioToSatellitesExcept(nullptr, tg, msg.audio());
|
||||
m_reflector->forwardAudioToSatellitesExcept(nullptr, local_tg, msg.audio());
|
||||
} /* TrunkLink::handleMsgTrunkAudio */
|
||||
|
||||
|
||||
@@ -797,17 +912,23 @@ void TrunkLink::handleMsgTrunkFlush(std::istream& is)
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (!isOwnedTG(tg) && !m_reflector->isClusterTG(tg))
|
||||
uint32_t wire_tg = msg.tg();
|
||||
uint32_t local_tg = mapTgIn(wire_tg);
|
||||
if (isBlacklisted(wire_tg) || isBlacklisted(local_tg) || !isAllowed(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool mapped = m_tg_map_in.count(wire_tg) > 0;
|
||||
if (!mapped && !isOwnedTG(wire_tg) && !m_reflector->isClusterTG(wire_tg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||
ReflectorClient::TgFilter(tg));
|
||||
ReflectorClient::TgFilter(local_tg));
|
||||
|
||||
// Forward trunk flush to connected satellites
|
||||
m_reflector->forwardFlushToSatellitesExcept(nullptr, tg);
|
||||
m_reflector->forwardFlushToSatellitesExcept(nullptr, local_tg);
|
||||
} /* TrunkLink::handleMsgTrunkFlush */
|
||||
|
||||
|
||||
@@ -970,6 +1091,90 @@ void TrunkLink::clearPeerTalkerState(void)
|
||||
} /* TrunkLink::clearPeerTalkerState */
|
||||
|
||||
|
||||
void TrunkLink::reloadConfig(void)
|
||||
{
|
||||
m_blacklist_filter = TgFilter{};
|
||||
m_allow_filter = TgFilter{};
|
||||
m_tg_map_in.clear();
|
||||
m_tg_map_out.clear();
|
||||
|
||||
std::string blacklist_str;
|
||||
if (m_cfg.getValue(m_section, "BLACKLIST_TGS", blacklist_str)
|
||||
&& !blacklist_str.empty())
|
||||
{
|
||||
m_blacklist_filter = TgFilter::parse(blacklist_str);
|
||||
}
|
||||
|
||||
std::string allow_str;
|
||||
if (m_cfg.getValue(m_section, "ALLOW_TGS", allow_str) && !allow_str.empty())
|
||||
{
|
||||
m_allow_filter = TgFilter::parse(allow_str);
|
||||
}
|
||||
|
||||
std::string tgmap_str;
|
||||
if (m_cfg.getValue(m_section, "TG_MAP", tgmap_str) && !tgmap_str.empty())
|
||||
{
|
||||
std::istringstream ms(tgmap_str);
|
||||
std::string pair;
|
||||
while (std::getline(ms, pair, ','))
|
||||
{
|
||||
auto colon = pair.find(':');
|
||||
if (colon == std::string::npos) continue;
|
||||
try {
|
||||
uint32_t peer_tg = std::stoul(pair.substr(0, colon));
|
||||
uint32_t local_tg = std::stoul(pair.substr(colon + 1));
|
||||
m_tg_map_in[peer_tg] = local_tg;
|
||||
m_tg_map_out[local_tg] = peer_tg;
|
||||
} catch (...) { /* skip malformed */ }
|
||||
}
|
||||
}
|
||||
|
||||
cout << m_section << ": Reloaded filters"
|
||||
<< (m_blacklist_filter.empty() ? "" :
|
||||
" blacklist=" + m_blacklist_filter.toString())
|
||||
<< (m_allow_filter.empty() ? "" :
|
||||
" allow=" + m_allow_filter.toString())
|
||||
<< " tg_map_entries=" << m_tg_map_in.size() << endl;
|
||||
} /* TrunkLink::reloadConfig */
|
||||
|
||||
|
||||
void TrunkLink::sendNodeList(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgTrunkNodeList(nodes));
|
||||
} /* TrunkLink::sendNodeList */
|
||||
|
||||
|
||||
void TrunkLink::handleMsgTrunkNodeList(std::istream& is)
|
||||
{
|
||||
MsgTrunkNodeList msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cerr << "*** ERROR[" << m_section
|
||||
<< "]: Failed to unpack MsgTrunkNodeList" << endl;
|
||||
return;
|
||||
}
|
||||
m_reflector->onPeerNodeList(peerId(), msg.nodes());
|
||||
} /* TrunkLink::handleMsgTrunkNodeList */
|
||||
|
||||
|
||||
std::string TrunkLink::statusLine(void) const
|
||||
{
|
||||
ostringstream s;
|
||||
s << m_section
|
||||
<< " peer_id=" << peerId()
|
||||
<< " ob=" << (isOutboundReady() ? "up" : "down")
|
||||
<< " ib=" << (isInboundReady() ? "up" : "down")
|
||||
<< " active_tgs=" << m_peer_active_tgs.size()
|
||||
<< " muted=" << m_muted_callsigns.size()
|
||||
<< (m_blacklist_filter.empty() ? "" : " [blacklist]")
|
||||
<< (m_allow_filter.empty() ? "" : " [allow]")
|
||||
<< (m_tg_map_in.empty() ? "" : " [tg_map]");
|
||||
return s.str();
|
||||
} /* TrunkLink::statusLine */
|
||||
|
||||
|
||||
/*
|
||||
* This file has not been truncated
|
||||
*/
|
||||
@@ -52,6 +52,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <AsyncFramedTcpConnection.h>
|
||||
#include <AsyncTimer.h>
|
||||
|
||||
#include "TgFilter.h"
|
||||
#include "ReflectorMsg.h"
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
@@ -103,6 +106,10 @@ class TrunkLink : public sigc::trackable
|
||||
m_all_prefixes = all_prefixes;
|
||||
}
|
||||
const std::string& section(void) const { return m_section; }
|
||||
const std::string& peerId(void) const
|
||||
{
|
||||
return m_peer_id_received.empty() ? m_section : m_peer_id_received;
|
||||
}
|
||||
|
||||
Json::Value statusJson(void) const;
|
||||
|
||||
@@ -130,6 +137,28 @@ class TrunkLink : public sigc::trackable
|
||||
// Called by Reflector when a local talker's audio stream ends
|
||||
void onLocalFlush(uint32_t tg);
|
||||
|
||||
// Send the local node list (callsign + current TG per local client)
|
||||
// to the peer. Called from Reflector after debounce.
|
||||
void sendNodeList(const std::vector<MsgTrunkNodeList::NodeEntry>& nodes);
|
||||
|
||||
// PTY-driven controls
|
||||
void muteCallsign(const std::string& callsign)
|
||||
{
|
||||
m_muted_callsigns.insert(callsign);
|
||||
}
|
||||
void unmuteCallsign(const std::string& callsign)
|
||||
{
|
||||
m_muted_callsigns.erase(callsign);
|
||||
}
|
||||
bool isCallsignMuted(const std::string& callsign) const
|
||||
{
|
||||
return m_muted_callsigns.count(callsign) > 0;
|
||||
}
|
||||
// Re-parse BLACKLIST_TGS, ALLOW_TGS and TG_MAP from current config
|
||||
void reloadConfig(void);
|
||||
// One-line summary for TRUNK STATUS
|
||||
std::string statusLine(void) const;
|
||||
|
||||
private:
|
||||
static const unsigned HEARTBEAT_TX_CNT_RESET = 10;
|
||||
static const unsigned HEARTBEAT_RX_CNT_RESET = 15;
|
||||
@@ -145,6 +174,8 @@ class TrunkLink : public sigc::trackable
|
||||
std::string m_peer_host;
|
||||
uint16_t m_peer_port;
|
||||
std::string m_secret;
|
||||
std::string m_peer_id_config; // our hello id (from PEER_ID; defaults to section)
|
||||
std::string m_peer_id_received; // peer's hello id (set on hello rx)
|
||||
std::vector<std::string> m_local_prefix; // our authoritative TG prefixes
|
||||
std::vector<std::string> m_remote_prefix; // peer's authoritative TG prefixes
|
||||
uint32_t m_priority; // our tie-break nonce (random, set once)
|
||||
@@ -153,6 +184,11 @@ class TrunkLink : public sigc::trackable
|
||||
Async::FramedTcpConnection* m_inbound_con = nullptr; // accepted inbound
|
||||
Async::Timer m_heartbeat_timer;
|
||||
std::vector<std::string> m_all_prefixes; // all prefixes in the mesh
|
||||
TgFilter m_blacklist_filter; // TGs never carried on this link
|
||||
TgFilter m_allow_filter; // if non-empty: only these TGs pass
|
||||
std::map<uint32_t, uint32_t> m_tg_map_in; // peer wire TG -> local TG
|
||||
std::map<uint32_t, uint32_t> m_tg_map_out; // local TG -> peer wire TG
|
||||
std::set<std::string> m_muted_callsigns;
|
||||
// TGs where we suppressed our local talker to defer to the peer
|
||||
std::set<uint32_t> m_yielded_tgs;
|
||||
// TGs currently held by this specific trunk peer (for scoped cleanup)
|
||||
@@ -180,6 +216,18 @@ class TrunkLink : public sigc::trackable
|
||||
bool isInboundReady(void) const;
|
||||
bool isOwnedTG(uint32_t tg) const;
|
||||
bool isPeerInterestedTG(uint32_t tg) const;
|
||||
bool isBlacklisted(uint32_t tg) const;
|
||||
bool isAllowed(uint32_t tg) const;
|
||||
uint32_t mapTgIn(uint32_t peer_tg) const
|
||||
{
|
||||
auto it = m_tg_map_in.find(peer_tg);
|
||||
return (it != m_tg_map_in.end()) ? it->second : peer_tg;
|
||||
}
|
||||
uint32_t mapTgOut(uint32_t local_tg) const
|
||||
{
|
||||
auto it = m_tg_map_out.find(local_tg);
|
||||
return (it != m_tg_map_out.end()) ? it->second : local_tg;
|
||||
}
|
||||
|
||||
void onConnected(void);
|
||||
void onDisconnected(Async::TcpConnection* con,
|
||||
@@ -193,6 +241,7 @@ class TrunkLink : public sigc::trackable
|
||||
void handleMsgTrunkAudio(std::istream& is);
|
||||
void handleMsgTrunkFlush(std::istream& is);
|
||||
void handleMsgTrunkHeartbeat(void);
|
||||
void handleMsgTrunkNodeList(std::istream& is);
|
||||
|
||||
void sendMsg(const ReflectorMsg& msg);
|
||||
void sendMsgOnOutbound(const ReflectorMsg& msg);
|
||||
|
||||
@@ -104,6 +104,17 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py
|
||||
#PORT=5302
|
||||
#SECRET=change_this_shared_secret
|
||||
#REMOTE_PREFIX=2
|
||||
# Optional PEER_ID — name advertised to the peer in the trunk hello
|
||||
# (defaults to section name). The peer uses it as the MQTT topic
|
||||
# component for this link, so set it to a stable, broker-friendly name.
|
||||
#PEER_ID=reflector-a
|
||||
# Optional per-trunk TG filters (syntax: exact "26200", prefix "24*",
|
||||
# range "2427-2438", comma-separated):
|
||||
#BLACKLIST_TGS=666,777* # never carried in either direction on this link
|
||||
#ALLOW_TGS=24*,2624123 # if set, ONLY these TGs are exchanged
|
||||
# Optional bidirectional TG remap (peer_tg:local_tg, comma-separated).
|
||||
# Mapped TGs bypass the prefix routing check on this link.
|
||||
#TG_MAP=1:2624123,2:2624124
|
||||
|
||||
# --- Satellite reflectors ---
|
||||
# A satellite is a lightweight reflector that connects to a parent
|
||||
@@ -136,6 +147,10 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py
|
||||
#USERNAME=reflector
|
||||
#PASSWORD=secret
|
||||
#TOPIC_PREFIX=svxreflector/myreflector
|
||||
# Optional MQTT_NAME — appended as a path component, so topics become
|
||||
# <TOPIC_PREFIX>/<MQTT_NAME>/... — useful when several reflectors share
|
||||
# the same TOPIC_PREFIX. Leave unset to keep topics flat.
|
||||
#MQTT_NAME=reflector-01
|
||||
#STATUS_INTERVAL=1000
|
||||
#TLS_ENABLED=0
|
||||
#TLS_CA_CERT=/path/to/ca.crt
|
||||
|
||||
Reference in new issue
Block a user