sat: full partner-node parity across reflector + satellites
Extends MsgTrunkNodeList (type 121) with a 7th vector `sat_ids` so a
parent reflector can advertise both its own clients (sat_id="") and
clients learned from each connected satellite (sat_id=<satellite_id>)
in a single message. The sat_id is recipient-relative — empty means
"on whoever sent this list" — so the same field is reused on the
trunk, twin and satellite paths without a global namespace.
Reflector::sendNodeListToAllPeers now builds a combined view (parent-
local + every connected satellite's stamped roster) and fans it out:
- to trunks and twin: full combined list
- to each satellite: combined minus that sat's own contribution,
additionally filtered by SATELLITE_FILTER (self-echo guard +
audio-path scoping)
- up to the parent (when running as a satellite): local clients only
SatelliteLink (parent side) and SatelliteClient (sat side) gain
sendNodeList / handleMsgTrunkNodeList wired into the type-121 dispatch.
Parent stamps each ingested entry with the SatelliteLink's id, then
schedules a debounced re-broadcast so trunk peers and sibling sats see
the new contribution. /status now exposes:
- parent: /status.satellites[<id>].nodes (per-sat partner roster)
- parent: /status.trunks[*].nodes[*].sat_id (attribution)
- satellite: /status.satellite.parent_nodes (parent's combined view)
Result: refA, S1, S2 all render the same set of callsigns, with each
entry tagged so consumers can tell where it physically lives.
Wire-format note: this is the second lockstep bump on type 121 within
~24h of a3757ca. Peers running an older fork build will fail to unpack
and silently empty their partner roster until upgraded; pre-jay peers
keep ignoring it.
Tests: 35 → 39. Three /status-level checks (sat-attached client visible
on parent, on far-trunk peer with sat_id, parent-local visible on
satellite) plus a multi-sat wire-level cross-visibility test that
verifies sat_id stamping and the self-echo guard.
This commit is contained in:
1 parent
d9ec356f10
commit
3d281e16d7
10 files changed
+761
-41
No files matched your search
@@ -1768,6 +1768,30 @@ void Reflector::refreshStatus(void)
|
||||
sat_cfg["parent_host"] = sat_of;
|
||||
if (!sat_port_str.empty()) sat_cfg["parent_port"] = sat_port_str;
|
||||
if (!sat_id.empty()) sat_cfg["id"] = sat_id;
|
||||
if (m_satellite_client != nullptr)
|
||||
{
|
||||
const auto& parent_id = m_satellite_client->parentId();
|
||||
if (!parent_id.empty()) sat_cfg["parent_id"] = parent_id;
|
||||
Json::Value pnodes(Json::arrayValue);
|
||||
for (const auto& n : m_satellite_client->parentNodes())
|
||||
{
|
||||
Json::Value entry = n.status.isObject()
|
||||
? n.status : Json::Value(Json::objectValue);
|
||||
entry["callsign"] = n.callsign;
|
||||
entry["tg"] = static_cast<Json::UInt>(n.tg);
|
||||
if (n.lat != 0.0f || n.lon != 0.0f)
|
||||
{
|
||||
entry["lat"] = n.lat;
|
||||
entry["lon"] = n.lon;
|
||||
}
|
||||
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
|
||||
if (!n.sat_id.empty()) entry["sat_id"] = n.sat_id;
|
||||
entry["isTalker"] =
|
||||
(TGHandler::instance()->trunkTalkerForTG(n.tg) == n.callsign);
|
||||
pnodes.append(entry);
|
||||
}
|
||||
sat_cfg["parent_nodes"] = pnodes;
|
||||
}
|
||||
m_status["satellite"] = sat_cfg;
|
||||
}
|
||||
else
|
||||
@@ -3218,7 +3242,8 @@ void Reflector::scheduleNodeListUpdate(void)
|
||||
|
||||
void Reflector::sendNodeListToAllPeers(void)
|
||||
{
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> nodes;
|
||||
// 1. Local clients — sat_id stays empty (recipient-relative: "on me").
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> local_nodes;
|
||||
for (const auto& kv : m_client_con_map)
|
||||
{
|
||||
ReflectorClient* c = kv.second;
|
||||
@@ -3248,22 +3273,63 @@ void Reflector::sendNodeListToAllPeers(void)
|
||||
e.qth_name = qth["name"].asString();
|
||||
}
|
||||
}
|
||||
nodes.push_back(e);
|
||||
local_nodes.push_back(e);
|
||||
}
|
||||
|
||||
// 2. Combined view = local + every connected satellite's stamped roster.
|
||||
// Each sat-supplied entry already carries sat_id == its satelliteId.
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> combined = local_nodes;
|
||||
for (const auto& kv : m_satellite_con_map)
|
||||
{
|
||||
const auto& sat_nodes = kv.second->partnerNodes();
|
||||
combined.insert(combined.end(), sat_nodes.begin(), sat_nodes.end());
|
||||
}
|
||||
|
||||
// 3. Trunks and twin: full combined view. Trunk peers and twin partners
|
||||
// see the parent's clients (sat_id="") and every satellite's clients
|
||||
// (sat_id=<sat_id>) in a single list.
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->sendNodeList(nodes);
|
||||
link->sendNodeList(combined);
|
||||
}
|
||||
|
||||
if (m_twin_link != nullptr)
|
||||
{
|
||||
m_twin_link->onLocalNodeListUpdated(nodes);
|
||||
m_twin_link->onLocalNodeListUpdated(combined);
|
||||
}
|
||||
|
||||
// 4. Each satellite gets the combined view minus its own contribution
|
||||
// (self-echo guard: a satellite must not be told about its own
|
||||
// clients). SatelliteLink::sendNodeList additionally applies that
|
||||
// satellite's announced TG filter.
|
||||
for (const auto& kv : m_satellite_con_map)
|
||||
{
|
||||
SatelliteLink* link = kv.second;
|
||||
const std::string& this_sat_id = link->satelliteId();
|
||||
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> for_this_sat;
|
||||
for_this_sat.reserve(combined.size());
|
||||
for (const auto& n : combined)
|
||||
{
|
||||
if (!this_sat_id.empty() && n.sat_id == this_sat_id) continue;
|
||||
for_this_sat.push_back(n);
|
||||
}
|
||||
link->sendNodeList(for_this_sat);
|
||||
}
|
||||
|
||||
// 5. If we are a satellite ourselves, advertise our local roster up to
|
||||
// the parent. We send local clients only (sat_id=""); any deeper
|
||||
// satellite hierarchy is collapsed by the parent's ingest stamping.
|
||||
if (m_is_satellite && m_satellite_client != nullptr)
|
||||
{
|
||||
m_satellite_client->sendNodeList(local_nodes);
|
||||
}
|
||||
|
||||
// 6. MQTT — keep scope to parent-local clients (sat-supplied entries
|
||||
// already get a publish via SatelliteLink::handleMsgTrunkNodeList
|
||||
// calling onPeerNodeList → MqttPublisher::publishPeerNodes).
|
||||
if (m_mqtt != nullptr)
|
||||
{
|
||||
m_mqtt->publishLocalNodes(nodes);
|
||||
m_mqtt->publishLocalNodes(local_nodes);
|
||||
}
|
||||
} /* Reflector::sendNodeListToAllPeers */
|
||||
|
||||
|
||||
@@ -1829,16 +1829,23 @@ Sent by a reflector to its trunk peer whenever its local client list changes
|
||||
MQTT publisher. Older peers that don't know type 121 ignore it — fully
|
||||
backward compatible.
|
||||
|
||||
Each entry carries callsign, current TG, optional lat/lon/QTH name, and
|
||||
Each entry carries callsign, current TG, optional lat/lon/QTH name,
|
||||
the full per-client status blob (rx/tx config, qth array, monitoredTGs,
|
||||
restrictedTG, protoVer, ...) so that a peer's /status, MQTT topic and
|
||||
Redis snapshot can render partner nodes with the same richness as local
|
||||
ones. The blob is the source reflector's `m_status["nodes"][callsign]`
|
||||
JSON serialised verbatim; receivers parse and sanitise it.
|
||||
restrictedTG, protoVer, ...), and an optional sat_id tagging the
|
||||
satellite the client is actually attached to (empty when the client is
|
||||
on the sender directly). The blob is the source reflector's
|
||||
`m_status["nodes"][callsign]` JSON serialised verbatim; receivers parse
|
||||
and sanitise it.
|
||||
|
||||
Wire-format note: extending this message (m_status_blobs added on top of
|
||||
the original 5 vectors) is NOT compatible with peers running an older
|
||||
build of the same fork — the unpack expects exactly six vectors. All
|
||||
The sat_id is interpreted recipient-relative: an empty string means
|
||||
"directly attached to whoever sent me this list." Used so that when a
|
||||
parent reflector advertises both its own clients and clients learned
|
||||
from its satellites, the recipient (a trunk peer or another satellite)
|
||||
can tell them apart.
|
||||
|
||||
Wire-format note: this message has been extended TWICE — first to add
|
||||
m_status_blobs, then to add m_sat_ids. Each extension is a hard
|
||||
lockstep bump because the unpack expects an exact vector count. All
|
||||
peers in a mesh must be upgraded together.
|
||||
*/
|
||||
class MsgTrunkNodeList : public ReflectorMsgBase<121>
|
||||
@@ -1853,6 +1860,9 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
|
||||
std::string qth_name;
|
||||
Json::Value status; // rich per-client status; transported as
|
||||
// m_status_blobs[i] over the wire
|
||||
std::string sat_id; // empty = on sender directly; otherwise
|
||||
// satellite_id of the satellite attached to
|
||||
// the sender that this client lives on
|
||||
};
|
||||
|
||||
MsgTrunkNodeList(void) {}
|
||||
@@ -1870,6 +1880,7 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
|
||||
m_status_blobs.push_back(
|
||||
n.status.isNull() ? std::string()
|
||||
: Json::writeString(wb, n.status));
|
||||
m_sat_ids.push_back(n.sat_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1901,13 +1912,14 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
|
||||
}
|
||||
}
|
||||
}
|
||||
e.sat_id = (i < m_sat_ids.size()) ? m_sat_ids[i] : "";
|
||||
result.push_back(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ASYNC_MSG_MEMBERS(m_callsigns, m_tgs, m_lats, m_lons, m_qth_names,
|
||||
m_status_blobs)
|
||||
m_status_blobs, m_sat_ids)
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_callsigns;
|
||||
@@ -1916,6 +1928,7 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
|
||||
std::vector<float> m_lons;
|
||||
std::vector<std::string> m_qth_names;
|
||||
std::vector<std::string> m_status_blobs;
|
||||
std::vector<std::string> m_sat_ids;
|
||||
}; /* MsgTrunkNodeList */
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
@@ -16,6 +17,75 @@ using namespace std;
|
||||
using namespace Async;
|
||||
using namespace sigc;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string sanitizeIdent(const std::string& in, size_t max_len)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(std::min(in.size(), max_len));
|
||||
for (char c : in)
|
||||
{
|
||||
unsigned char u = static_cast<unsigned char>(c);
|
||||
if (u < 0x20 || u == 0x7f) continue;
|
||||
if (c == ':') continue;
|
||||
out += c;
|
||||
if (out.size() >= max_len) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string sanitizeText(const std::string& in, size_t max_bytes)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(std::min(in.size(), max_bytes));
|
||||
for (char c : in)
|
||||
{
|
||||
unsigned char u = static_cast<unsigned char>(c);
|
||||
if (u < 0x20 || u == 0x7f) continue;
|
||||
out += c;
|
||||
if (out.size() >= max_bytes) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void sanitizeJsonStrings(Json::Value& v, unsigned depth = 0)
|
||||
{
|
||||
static constexpr unsigned MAX_DEPTH = 8;
|
||||
static constexpr Json::ArrayIndex MAX_LEN = 256;
|
||||
static constexpr size_t MAX_STR_BYTES = 1024;
|
||||
if (depth >= MAX_DEPTH) { v = Json::Value(); return; }
|
||||
if (v.isString())
|
||||
{
|
||||
v = sanitizeText(v.asString(), MAX_STR_BYTES);
|
||||
}
|
||||
else if (v.isArray())
|
||||
{
|
||||
if (v.size() > MAX_LEN) v.resize(MAX_LEN);
|
||||
for (Json::ArrayIndex i = 0; i < v.size(); ++i)
|
||||
{
|
||||
sanitizeJsonStrings(v[i], depth + 1);
|
||||
}
|
||||
}
|
||||
else if (v.isObject())
|
||||
{
|
||||
auto names = v.getMemberNames();
|
||||
if (names.size() > MAX_LEN)
|
||||
{
|
||||
for (size_t i = MAX_LEN; i < names.size(); ++i)
|
||||
{
|
||||
v.removeMember(names[i]);
|
||||
}
|
||||
names.resize(MAX_LEN);
|
||||
}
|
||||
for (const auto& k : names)
|
||||
{
|
||||
sanitizeJsonStrings(v[k], depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
SatelliteClient::SatelliteClient(Reflector* reflector, Async::Config& cfg)
|
||||
: m_reflector(reflector), m_cfg(cfg),
|
||||
@@ -143,6 +213,15 @@ void SatelliteClient::onDisconnected(TcpConnection* con,
|
||||
m_heartbeat_timer.setEnable(false);
|
||||
m_hello_received = false;
|
||||
TGHandler::instance()->clearAllTrunkTalkers();
|
||||
|
||||
if (!m_parent_nodes.empty() && !m_parent_id.empty())
|
||||
{
|
||||
// Tombstone-clear Redis live:peer_node:<parent_id>:* and let MQTT
|
||||
// emit an empty list so consumers see the partner roster drop.
|
||||
m_reflector->onPeerNodeList(m_parent_id,
|
||||
std::vector<MsgTrunkNodeList::NodeEntry>{});
|
||||
m_parent_nodes.clear();
|
||||
}
|
||||
} /* SatelliteClient::onDisconnected */
|
||||
|
||||
|
||||
@@ -189,6 +268,9 @@ void SatelliteClient::onFrameReceived(FramedTcpConnection* con,
|
||||
case MsgTrunkFlush::TYPE:
|
||||
handleMsgTrunkFlush(ss);
|
||||
break;
|
||||
case MsgTrunkNodeList::TYPE:
|
||||
handleMsgTrunkNodeList(ss);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -217,11 +299,17 @@ void SatelliteClient::handleMsgTrunkHello(std::istream& is)
|
||||
}
|
||||
|
||||
m_hello_received = true;
|
||||
m_parent_id = sanitizeIdent(msg.id(), 64);
|
||||
geulog::info("satellite", "Parent authenticated (id='", msg.id(), "')");
|
||||
|
||||
// Advertise our TG filter to the parent so it can skip TGs we
|
||||
// don't want. The parent applies the filter on its outbound path.
|
||||
sendFilter();
|
||||
|
||||
// Trigger the reflector to push our local roster up immediately so the
|
||||
// parent can fan it out (debounced) — otherwise the first node-list
|
||||
// emission only happens on the next client login/TG-change.
|
||||
m_reflector->scheduleNodeListUpdate();
|
||||
} /* SatelliteClient::handleMsgTrunkHello */
|
||||
|
||||
|
||||
@@ -276,6 +364,72 @@ void SatelliteClient::handleMsgTrunkFlush(std::istream& is)
|
||||
} /* SatelliteClient::handleMsgTrunkFlush */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkNodeList(std::istream& is)
|
||||
{
|
||||
MsgTrunkNodeList msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("satellite", "Failed to unpack MsgTrunkNodeList");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> sanitized;
|
||||
sanitized.reserve(msg.nodes().size());
|
||||
unsigned dropped = 0;
|
||||
for (const auto& n : msg.nodes())
|
||||
{
|
||||
MsgTrunkNodeList::NodeEntry e;
|
||||
e.callsign = sanitizeIdent(n.callsign, 32);
|
||||
if (e.callsign.empty()) { ++dropped; continue; }
|
||||
e.tg = n.tg;
|
||||
e.qth_name = sanitizeText(n.qth_name, 64);
|
||||
if (std::isfinite(n.lat) && std::isfinite(n.lon) &&
|
||||
n.lat >= -90.0f && n.lat <= 90.0f &&
|
||||
n.lon >= -180.0f && n.lon <= 180.0f)
|
||||
{
|
||||
e.lat = n.lat;
|
||||
e.lon = n.lon;
|
||||
}
|
||||
e.status = n.status;
|
||||
sanitizeJsonStrings(e.status);
|
||||
// Recipient-relative sat_id from the parent passes through unchanged:
|
||||
// empty = "on the parent itself", non-empty = "on a sibling sat
|
||||
// attached to the parent".
|
||||
e.sat_id = sanitizeIdent(n.sat_id, 64);
|
||||
sanitized.push_back(std::move(e));
|
||||
}
|
||||
if (dropped > 0)
|
||||
{
|
||||
geulog::warn("satellite", "Dropped ", dropped,
|
||||
" parent-roster entrie(s) with empty/invalid callsign");
|
||||
}
|
||||
|
||||
if (!m_parent_id.empty())
|
||||
{
|
||||
m_reflector->onPeerNodeList(m_parent_id, sanitized);
|
||||
}
|
||||
m_parent_nodes = std::move(sanitized);
|
||||
} /* SatelliteClient::handleMsgTrunkNodeList */
|
||||
|
||||
|
||||
void SatelliteClient::sendNodeList(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
|
||||
// Apply our outbound TG filter so we only push roster entries the
|
||||
// parent cares about (consistent with the audio-path scoping rule).
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> filtered;
|
||||
filtered.reserve(nodes.size());
|
||||
for (const auto& n : nodes)
|
||||
{
|
||||
if (!m_filter.empty() && !m_filter.matches(n.tg)) continue;
|
||||
filtered.push_back(n);
|
||||
}
|
||||
sendMsg(MsgTrunkNodeList(filtered));
|
||||
} /* SatelliteClient::sendNodeList */
|
||||
|
||||
|
||||
void SatelliteClient::sendMsg(const ReflectorMsg& msg)
|
||||
{
|
||||
ostringstream ss;
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <AsyncTimer.h>
|
||||
|
||||
#include "TgFilter.h"
|
||||
#include "ReflectorMsg.h"
|
||||
|
||||
class Reflector;
|
||||
class ReflectorMsg;
|
||||
|
||||
/**
|
||||
@brief Satellite-side outbound connection to a parent reflector
|
||||
@@ -43,6 +43,19 @@ class SatelliteClient : public sigc::trackable
|
||||
void onLocalAudio(uint32_t tg, const std::vector<uint8_t>& audio);
|
||||
void onLocalFlush(uint32_t tg);
|
||||
|
||||
// Send our local roster up to the parent. Caller has already filtered
|
||||
// to "this satellite's local clients" (sat_id empty on the wire).
|
||||
void sendNodeList(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes);
|
||||
|
||||
// Read-only access to the parent's combined-view roster, surfaced
|
||||
// by Reflector::statusJson under /status.parent.nodes.
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& parentNodes(void) const
|
||||
{
|
||||
return m_parent_nodes;
|
||||
}
|
||||
const std::string& parentId(void) const { return m_parent_id; }
|
||||
|
||||
private:
|
||||
static const unsigned HEARTBEAT_TX_CNT_RESET = 10;
|
||||
static const unsigned HEARTBEAT_RX_CNT_RESET = 15;
|
||||
@@ -64,6 +77,12 @@ class SatelliteClient : public sigc::trackable
|
||||
unsigned m_hb_rx_cnt;
|
||||
TgFilter m_filter; // optional TG filter (SATELLITE_FILTER)
|
||||
std::string m_filter_str; // raw config string for MsgTrunkFilter
|
||||
// Parent's id from MsgTrunkHello (used as the peer_id key for Redis
|
||||
// tombstone bookkeeping when storing the parent-supplied roster).
|
||||
std::string m_parent_id;
|
||||
// Parent's combined roster (parent-local + every sibling satellite,
|
||||
// minus our own contribution). Surfaced via /status.parent.nodes.
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> m_parent_nodes;
|
||||
|
||||
void onConnected(void);
|
||||
void onDisconnected(Async::TcpConnection* con,
|
||||
@@ -76,6 +95,7 @@ class SatelliteClient : 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 sendFilter(void);
|
||||
void heartbeatTick(Async::Timer* t);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
@@ -12,6 +13,78 @@
|
||||
using namespace std;
|
||||
using namespace Async;
|
||||
|
||||
namespace {
|
||||
|
||||
// Byte-bound and strip control chars / ':' from an identifier coming over
|
||||
// the wire. Mirrors the sanitizer used in TrunkLink/TwinLink — wire data
|
||||
// flows into Redis key names, MQTT payloads and log output.
|
||||
std::string sanitizeIdent(const std::string& in, size_t max_len)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(std::min(in.size(), max_len));
|
||||
for (char c : in)
|
||||
{
|
||||
unsigned char u = static_cast<unsigned char>(c);
|
||||
if (u < 0x20 || u == 0x7f) continue;
|
||||
if (c == ':') continue;
|
||||
out += c;
|
||||
if (out.size() >= max_len) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string sanitizeText(const std::string& in, size_t max_bytes)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(std::min(in.size(), max_bytes));
|
||||
for (char c : in)
|
||||
{
|
||||
unsigned char u = static_cast<unsigned char>(c);
|
||||
if (u < 0x20 || u == 0x7f) continue;
|
||||
out += c;
|
||||
if (out.size() >= max_bytes) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void sanitizeJsonStrings(Json::Value& v, unsigned depth = 0)
|
||||
{
|
||||
static constexpr unsigned MAX_DEPTH = 8;
|
||||
static constexpr Json::ArrayIndex MAX_LEN = 256;
|
||||
static constexpr size_t MAX_STR_BYTES = 1024;
|
||||
if (depth >= MAX_DEPTH) { v = Json::Value(); return; }
|
||||
if (v.isString())
|
||||
{
|
||||
v = sanitizeText(v.asString(), MAX_STR_BYTES);
|
||||
}
|
||||
else if (v.isArray())
|
||||
{
|
||||
if (v.size() > MAX_LEN) v.resize(MAX_LEN);
|
||||
for (Json::ArrayIndex i = 0; i < v.size(); ++i)
|
||||
{
|
||||
sanitizeJsonStrings(v[i], depth + 1);
|
||||
}
|
||||
}
|
||||
else if (v.isObject())
|
||||
{
|
||||
auto names = v.getMemberNames();
|
||||
if (names.size() > MAX_LEN)
|
||||
{
|
||||
for (size_t i = MAX_LEN; i < names.size(); ++i)
|
||||
{
|
||||
v.removeMember(names[i]);
|
||||
}
|
||||
names.resize(MAX_LEN);
|
||||
}
|
||||
for (const auto& k : names)
|
||||
{
|
||||
sanitizeJsonStrings(v[k], depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
SatelliteLink::SatelliteLink(Reflector* reflector,
|
||||
Async::FramedTcpConnection* con,
|
||||
@@ -39,6 +112,15 @@ SatelliteLink::~SatelliteLink(void)
|
||||
TGHandler::instance()->clearTrunkTalkerForTG(tg);
|
||||
}
|
||||
m_sat_active_tgs.clear();
|
||||
// Drop any partner roster we held for this satellite so Reflector's
|
||||
// tombstone bookkeeping (Redis live:peer_node:<sat>:<callsign>) gets
|
||||
// a chance to clear those keys before we go away.
|
||||
if (!m_partner_nodes.empty() && !m_satellite_id.empty())
|
||||
{
|
||||
m_reflector->onPeerNodeList(m_satellite_id,
|
||||
std::vector<MsgTrunkNodeList::NodeEntry>{});
|
||||
m_partner_nodes.clear();
|
||||
}
|
||||
} /* SatelliteLink::~SatelliteLink */
|
||||
|
||||
|
||||
@@ -59,6 +141,27 @@ Json::Value SatelliteLink::statusJson(void) const
|
||||
{
|
||||
obj["filter"] = m_tg_filter.toString();
|
||||
}
|
||||
|
||||
Json::Value nodes_arr(Json::arrayValue);
|
||||
for (const auto& n : m_partner_nodes)
|
||||
{
|
||||
Json::Value entry = n.status.isObject() ? n.status
|
||||
: Json::Value(Json::objectValue);
|
||||
entry["callsign"] = n.callsign;
|
||||
entry["tg"] = static_cast<Json::UInt>(n.tg);
|
||||
if (n.lat != 0.0f || n.lon != 0.0f)
|
||||
{
|
||||
entry["lat"] = n.lat;
|
||||
entry["lon"] = n.lon;
|
||||
}
|
||||
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
|
||||
if (!n.sat_id.empty()) entry["sat_id"] = n.sat_id;
|
||||
entry["isTalker"] =
|
||||
(TGHandler::instance()->trunkTalkerForTG(n.tg) == n.callsign);
|
||||
nodes_arr.append(entry);
|
||||
}
|
||||
obj["nodes"] = nodes_arr;
|
||||
|
||||
return obj;
|
||||
} /* SatelliteLink::statusJson */
|
||||
|
||||
@@ -145,6 +248,9 @@ void SatelliteLink::onFrameReceived(FramedTcpConnection* con,
|
||||
case MsgTrunkFilter::TYPE:
|
||||
handleMsgTrunkFilter(ss);
|
||||
break;
|
||||
case MsgTrunkNodeList::TYPE:
|
||||
handleMsgTrunkNodeList(ss);
|
||||
break;
|
||||
default:
|
||||
geulog::warn("satellite", "Unknown message type=", header.type());
|
||||
break;
|
||||
@@ -201,6 +307,11 @@ void SatelliteLink::handleMsgTrunkHello(std::istream& is)
|
||||
sendMsg(MsgTrunkHello("PARENT", "", 0, m_secret,
|
||||
MsgTrunkHello::ROLE_PEER));
|
||||
|
||||
// Bring the new satellite up to speed: schedule a debounced node-list
|
||||
// emission so it receives the parent's combined view (parent-local
|
||||
// + every sibling satellite, minus its own contribution).
|
||||
m_reflector->scheduleNodeListUpdate();
|
||||
|
||||
statusChanged(this);
|
||||
} /* SatelliteLink::handleMsgTrunkHello */
|
||||
|
||||
@@ -343,3 +454,75 @@ bool SatelliteLink::filterPassesTg(uint32_t tg) const
|
||||
if (m_tg_filter.empty()) return true;
|
||||
return m_tg_filter.matches(tg);
|
||||
} /* SatelliteLink::filterPassesTg */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkNodeList(std::istream& is)
|
||||
{
|
||||
MsgTrunkNodeList msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("satellite", "Failed to unpack MsgTrunkNodeList from '",
|
||||
m_satellite_id, "'");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> sanitized;
|
||||
sanitized.reserve(msg.nodes().size());
|
||||
unsigned dropped = 0;
|
||||
for (const auto& n : msg.nodes())
|
||||
{
|
||||
MsgTrunkNodeList::NodeEntry e;
|
||||
e.callsign = sanitizeIdent(n.callsign, 32);
|
||||
if (e.callsign.empty()) { ++dropped; continue; }
|
||||
e.tg = n.tg;
|
||||
e.qth_name = sanitizeText(n.qth_name, 64);
|
||||
if (std::isfinite(n.lat) && std::isfinite(n.lon) &&
|
||||
n.lat >= -90.0f && n.lat <= 90.0f &&
|
||||
n.lon >= -180.0f && n.lon <= 180.0f)
|
||||
{
|
||||
e.lat = n.lat;
|
||||
e.lon = n.lon;
|
||||
}
|
||||
e.status = n.status;
|
||||
sanitizeJsonStrings(e.status);
|
||||
// Stamp every entry with this satellite's id. Wire sat_id from a
|
||||
// direct satellite is normally empty (its own clients are local to
|
||||
// it); a non-empty value would indicate a deeper sat-of-sat
|
||||
// hierarchy, which we collapse to a single level here.
|
||||
e.sat_id = m_satellite_id;
|
||||
sanitized.push_back(std::move(e));
|
||||
}
|
||||
if (dropped > 0)
|
||||
{
|
||||
geulog::warn("satellite", "'", m_satellite_id, "' dropped ", dropped,
|
||||
" node list entrie(s) with empty/invalid callsign");
|
||||
}
|
||||
|
||||
m_reflector->onPeerNodeList(m_satellite_id, sanitized);
|
||||
m_partner_nodes = std::move(sanitized);
|
||||
|
||||
// The parent's combined view changed — re-broadcast (debounced) to
|
||||
// trunks, twin, and sibling satellites so they pick up the new sat
|
||||
// contribution.
|
||||
m_reflector->scheduleNodeListUpdate();
|
||||
|
||||
statusChanged(this);
|
||||
} /* SatelliteLink::handleMsgTrunkNodeList */
|
||||
|
||||
|
||||
void SatelliteLink::sendNodeList(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
|
||||
// Apply this satellite's announced filter so we only forward TGs the
|
||||
// satellite cares about (matches the audio-path scoping rule).
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> filtered;
|
||||
filtered.reserve(nodes.size());
|
||||
for (const auto& n : nodes)
|
||||
{
|
||||
if (!filterPassesTg(n.tg)) continue;
|
||||
filtered.push_back(n);
|
||||
}
|
||||
sendMsg(MsgTrunkNodeList(filtered));
|
||||
} /* SatelliteLink::sendNodeList */
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <AsyncTimer.h>
|
||||
|
||||
#include "TgFilter.h"
|
||||
#include "ReflectorMsg.h"
|
||||
|
||||
class Reflector;
|
||||
class ReflectorMsg;
|
||||
|
||||
/**
|
||||
@brief Handles one inbound satellite connection on the parent reflector
|
||||
@@ -55,6 +55,22 @@ class SatelliteLink : public sigc::trackable
|
||||
void onParentAudio(uint32_t tg, const std::vector<uint8_t>& audio);
|
||||
void onParentFlush(uint32_t tg);
|
||||
|
||||
// Send a node list down to the satellite. Caller passes the combined
|
||||
// parent-known roster minus this satellite's own contribution; this
|
||||
// method additionally drops entries whose TG falls outside the
|
||||
// satellite's announced filter (if any).
|
||||
void sendNodeList(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes);
|
||||
|
||||
// Read-only access to the satellite-supplied roster (this satellite's
|
||||
// local clients), already sanitised and stamped with sat_id =
|
||||
// satelliteId(). Used by Reflector to merge into the parent's
|
||||
// outbound advertisements.
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& partnerNodes(void) const
|
||||
{
|
||||
return m_partner_nodes;
|
||||
}
|
||||
|
||||
private:
|
||||
static const unsigned HEARTBEAT_TX_CNT_RESET = 10;
|
||||
static const unsigned HEARTBEAT_RX_CNT_RESET = 15;
|
||||
@@ -69,6 +85,12 @@ class SatelliteLink : public sigc::trackable
|
||||
unsigned m_hb_rx_cnt;
|
||||
std::set<uint32_t> m_sat_active_tgs;
|
||||
TgFilter m_tg_filter;
|
||||
// Roster of clients attached to this satellite, learned via
|
||||
// MsgTrunkNodeList from the satellite. Each entry carries
|
||||
// sat_id == m_satellite_id (stamped on ingest) so the Reflector can
|
||||
// merge it into outbound trunk/twin/sibling-sat lists with correct
|
||||
// attribution.
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> m_partner_nodes;
|
||||
|
||||
void onFrameReceived(Async::FramedTcpConnection* con,
|
||||
std::vector<uint8_t>& data);
|
||||
@@ -79,6 +101,7 @@ class SatelliteLink : public sigc::trackable
|
||||
void handleMsgTrunkFlush(std::istream& is);
|
||||
void handleMsgTrunkHeartbeat(void);
|
||||
void handleMsgTrunkFilter(std::istream& is);
|
||||
void handleMsgTrunkNodeList(std::istream& is);
|
||||
bool filterPassesTg(uint32_t tg) const;
|
||||
void sendMsg(const ReflectorMsg& msg);
|
||||
void heartbeatTick(Async::Timer* t);
|
||||
|
||||
@@ -571,6 +571,7 @@ Json::Value TrunkLink::statusJson(void) const
|
||||
entry["lon"] = n.lon;
|
||||
}
|
||||
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
|
||||
if (!n.sat_id.empty()) entry["sat_id"] = n.sat_id;
|
||||
// Derive isTalker from the live trunk-talker map maintained by
|
||||
// MsgTrunkTalkerStart/Stop. Authoritative for partner nodes; the
|
||||
// sender's own isTalker is stale by the time it arrives in the
|
||||
@@ -1837,6 +1838,10 @@ void TrunkLink::handleMsgTrunkNodeList(std::istream& is)
|
||||
}
|
||||
e.status = n.status;
|
||||
sanitizeJsonStrings(e.status);
|
||||
// Recipient-relative sat_id from the peer. Pass through as-is after
|
||||
// bounded sanitisation: empty = "on the peer itself", non-empty =
|
||||
// "on a satellite attached to the peer".
|
||||
e.sat_id = sanitizeIdent(n.sat_id, 64);
|
||||
sanitized.push_back(std::move(e));
|
||||
}
|
||||
if (dropped > 0)
|
||||
|
||||
@@ -390,6 +390,7 @@ Json::Value TwinLink::statusJson(void) const
|
||||
entry["lon"] = n.lon;
|
||||
}
|
||||
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
|
||||
if (!n.sat_id.empty()) entry["sat_id"] = n.sat_id;
|
||||
entry["isTalker"] =
|
||||
(TGHandler::instance()->trunkTalkerForTG(n.tg) == n.callsign);
|
||||
nodes_arr.append(entry);
|
||||
@@ -691,6 +692,7 @@ void TwinLink::handleMsgTrunkNodeList(std::istream& is)
|
||||
}
|
||||
e.status = n.status;
|
||||
sanitizeJsonStrings(e.status);
|
||||
e.sat_id = sanitizeIdent(n.sat_id, 64);
|
||||
sanitized.push_back(std::move(e));
|
||||
}
|
||||
if (dropped > 0)
|
||||
|
||||
Reference in new issue
Block a user