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
@@ -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 */
|
||||
Reference in new issue
Block a user