trunk: ship rich per-client status blob in MsgTrunkNodeList (fixes #3)

Extends type 121 with a parallel string vector carrying each local
client's m_status["nodes"][callsign] verbatim. Receivers parse,
recursively sanitize (depth/length bounded), and surface the rich
blob under /status.trunks[*].nodes (and /status.twin.nodes), MQTT
nodes/<peer> and Redis live:peer_node:<peer>:<callsign>.status —
bringing partner nodes to parity with local-client status entries
(monitoredTGs, restrictedTG, qth, rx/tx config, protoVer, ...).

isTalker is derived on the receive side from the live trunk-talker
map (MsgTrunkTalkerStart/Stop) rather than carried in the blob,
since blob cadence is event-debounced login/logout/TG-change.

Lockstep wire bump: peers running an older fork build that knows
type 121 with the original 5-vector shape will fail to unpack and
silently empty their partner roster until upgraded. Pre-jayReflector
peers (no type 121 at all) keep ignoring it as before.
This commit is contained in:
Audric committed 2026-04-28 11:24:40 +02:00
1 parent 69c3c2eea3
commit a3757ca634
9 files changed
+217 -10

No files matched your search

+20 -1
View File
@@ -388,7 +388,7 @@ payload, packed using the `ASYNC_MSG_MEMBERS` macro.
| 118 | `MsgTrunkAudio` | `uint32 tg`, `uint8[] audio` |
| 119 | `MsgTrunkFlush` | `uint32 tg` |
| 120 | `MsgTrunkHeartbeat` | *(no fields)* |
| 121 | `MsgTrunkNodeList` | `string[] callsigns`, `uint32[] tgs`, `float[] lats`, `float[] lons`, `string[] qth_names` |
| 121 | `MsgTrunkNodeList` | `string[] callsigns`, `uint32[] tgs`, `float[] lats`, `float[] lons`, `string[] qth_names`, `string[] status_blobs` |
| 122 | `MsgTrunkFilter` | `string filter` (shared-syntax TG filter: exact / `24*` / `10-20`, comma-separated) |
Type numbers 115–120 are chosen to follow the last existing SvxReflector TCP
@@ -402,6 +402,25 @@ or TG change, debounced to 500 ms, and broadcast to every trunk peer. Peers
republish it via MQTT under `nodes/<peer_id>` so a central dashboard can see
who is connected to each reflector.
The optional `status_blobs[i]` field carries the source reflector's
`m_status["nodes"][callsign]` JSON serialised verbatim — the same rich
per-client status that local clients expose (rx/tx config, qth array,
monitoredTGs, restrictedTG, protoVer, ...). Receivers parse and recursively
sanitise it (depth/length caps, control-char strip) before surfacing it
under `/status.trunks[<section>].nodes[i]`, MQTT `nodes/<peer_id>`, and
the `status` field of Redis hash `live:peer_node:<peer_id>:<callsign>`.
The `isTalker` flag on each peer node is **not** carried in the blob (it
would be stale by the time it arrives); it is derived on the receive side
from the live trunk-talker map maintained by `MsgTrunkTalkerStart` /
`MsgTrunkTalkerStop`.
Wire-format note: extending this message (the `status_blobs` vector was
added on top of the original 5 vectors) is a lockstep change. A peer
running an older fork build that knows type 121 but expects only 5
vectors will fail to unpack and reject the message, which silently empties
the partner roster on that peer until it is upgraded. Peers that don't
know type 121 at all (pre-jayReflector) keep ignoring it as before.
`MsgTrunkFilter` is used by satellite links to advertise TG interest to the
parent. A satellite with `SATELLITE_FILTER` set sends one `MsgTrunkFilter`
right after authenticating; the parent stores the filter and skips forwarding
+4 -1
View File
@@ -334,7 +334,10 @@ static Json::Value nodeListToJson(
Json::Value arr(Json::arrayValue);
for (const auto& n : nodes)
{
Json::Value e;
// Prefer the rich per-client status blob; fall back to the flat
// wire fields if the source didn't ship one (older fork builds).
Json::Value e = n.status.isObject() ? n.status
: Json::Value(Json::objectValue);
e["callsign"] = n.callsign;
e["tg"] = n.tg;
if (n.lat != 0.0f || n.lon != 0.0f)
+5 -1
View File
@@ -386,7 +386,8 @@ void RedisStore::pushPeerNode(const std::string& peer_id,
const std::string& callsign,
uint32_t tg,
float lat, float lon,
const std::string& qth_name) {
const std::string& qth_name,
const std::string& status_json) {
if (!m_live_queue) return;
RedisLiveQueue::Op op;
op.op = RedisLiveQueue::OpType::HSET;
@@ -405,6 +406,9 @@ void RedisStore::pushPeerNode(const std::string& peer_id,
if (!qth_name.empty()) {
op.fields.emplace_back("qth_name", qth_name);
}
if (!status_json.empty()) {
op.fields.emplace_back("status", status_json);
}
op.ttl_s = 60;
m_live_queue->push(std::move(op));
}
+4 -2
View File
@@ -108,7 +108,8 @@ class RedisStore : public sigc::trackable
const std::string& callsign,
uint32_t tg,
float lat, float lon,
const std::string& qth_name);
const std::string& qth_name,
const std::string& status_json = std::string());
void clearPeerNode(const std::string& peer_id,
const std::string& callsign);
@@ -216,7 +217,8 @@ class RedisStore : public sigc::trackable
void pushLiveTrunk(const std::string&, const std::string&,
const std::string&) {}
void pushPeerNode(const std::string&, const std::string&, uint32_t,
float, float, const std::string&) {}
float, float, const std::string&,
const std::string& = std::string()) {}
void clearPeerNode(const std::string&, const std::string&) {}
uint64_t droppedLiveWrites(void) const { return 0; }
+28 -1
View File
@@ -3218,6 +3218,28 @@ void Reflector::sendNodeListToAllPeers(void)
MsgTrunkNodeList::NodeEntry e;
e.callsign = c->callsign();
e.tg = c->currentTG();
// Attach the rich per-client status blob so peers can render partner
// nodes with the same fidelity as local ones (rx/tx config, qth,
// monitoredTGs, restrictedTG, protoVer, ...). Receive side derives
// isTalker from existing trunk-talker events, so we don't need to
// push that field here.
if (m_status["nodes"].isMember(c->callsign()))
{
e.status = m_status["nodes"][c->callsign()];
// Opportunistically populate the legacy flat fields from the blob
// so they remain sensible on the wire.
if (e.status.isMember("qth") && e.status["qth"].isArray() &&
!e.status["qth"].empty())
{
const Json::Value& qth = e.status["qth"][0];
if (qth.isMember("lat") && qth["lat"].isNumeric())
e.lat = qth["lat"].asFloat();
if (qth.isMember("lon") && qth["lon"].isNumeric())
e.lon = qth["lon"].asFloat();
if (qth.isMember("name") && qth["name"].isString())
e.qth_name = qth["name"].asString();
}
}
nodes.push_back(e);
}
@@ -3248,13 +3270,18 @@ void Reflector::onPeerNodeList(const std::string& peer_id,
if (m_redis != nullptr && !peer_id.empty())
{
Json::StreamWriterBuilder wb;
wb["indentation"] = "";
std::set<std::string> seen;
for (const auto& n : nodes)
{
if (n.callsign.empty()) continue;
seen.insert(n.callsign);
const std::string status_json =
n.status.isNull() ? std::string()
: Json::writeString(wb, n.status);
m_redis->pushPeerNode(peer_id, n.callsign, n.tg,
n.lat, n.lon, n.qth_name);
n.lat, n.lon, n.qth_name, status_json);
}
auto& prev = m_peer_node_cache[peer_id];
for (const std::string& cs : prev)
+39 -2
View File
@@ -37,6 +37,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <openssl/rand.h>
#include <openssl/evp.h>
#include <vector>
#include <sstream>
#include <json/json.h>
#include <Log.h>
@@ -1827,7 +1829,17 @@ 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: callsign, current TG, optional lat/lon/QTH name.
Each entry carries callsign, current TG, optional lat/lon/QTH name, and
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.
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
peers in a mesh must be upgraded together.
*/
class MsgTrunkNodeList : public ReflectorMsgBase<121>
{
@@ -1839,11 +1851,15 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
float lat = 0.0f;
float lon = 0.0f;
std::string qth_name;
Json::Value status; // rich per-client status; transported as
// m_status_blobs[i] over the wire
};
MsgTrunkNodeList(void) {}
explicit MsgTrunkNodeList(const std::vector<NodeEntry>& nodes)
{
Json::StreamWriterBuilder wb;
wb["indentation"] = "";
for (const auto& n : nodes)
{
m_callsigns.push_back(n.callsign);
@@ -1851,6 +1867,9 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
m_lats.push_back(n.lat);
m_lons.push_back(n.lon);
m_qth_names.push_back(n.qth_name);
m_status_blobs.push_back(
n.status.isNull() ? std::string()
: Json::writeString(wb, n.status));
}
}
@@ -1866,12 +1885,29 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
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] : "";
if (i < m_status_blobs.size() && !m_status_blobs[i].empty())
{
// Bound parse cost: refuse blobs > 64 KiB. A typical client
// status blob is well under a kilobyte.
if (m_status_blobs[i].size() <= 65536u)
{
std::istringstream ss(m_status_blobs[i]);
Json::CharReaderBuilder rb;
std::string err;
Json::Value v;
if (Json::parseFromStream(rb, ss, &v, &err))
{
e.status = v;
}
}
}
result.push_back(e);
}
return result;
}
ASYNC_MSG_MEMBERS(m_callsigns, m_tgs, m_lats, m_lons, m_qth_names)
ASYNC_MSG_MEMBERS(m_callsigns, m_tgs, m_lats, m_lons, m_qth_names,
m_status_blobs)
private:
std::vector<std::string> m_callsigns;
@@ -1879,6 +1915,7 @@ class MsgTrunkNodeList : public ReflectorMsgBase<121>
std::vector<float> m_lats;
std::vector<float> m_lons;
std::vector<std::string> m_qth_names;
std::vector<std::string> m_status_blobs;
}; /* MsgTrunkNodeList */
+56 -1
View File
@@ -113,6 +113,50 @@ static std::string sanitizeText(const std::string& in, size_t max_bytes)
return out;
}
// Recursively sanitize string values inside an untrusted JSON tree
// received from a peer. Caps depth, container size, and per-string
// length. Mutates in place.
static 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(); // null out the subtree
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)
{
// Trim deterministically by removing trailing keys.
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);
}
}
}
static std::vector<std::string> splitPrefixes(const std::string& s)
{
std::vector<std::string> result;
@@ -515,7 +559,10 @@ Json::Value TrunkLink::statusJson(void) const
Json::Value nodes_arr(Json::arrayValue);
for (const auto& n : m_partner_nodes)
{
Json::Value entry(Json::objectValue);
// Start from the rich blob if present; fall back to the flat fields
// when the peer didn't supply one.
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)
@@ -524,6 +571,12 @@ Json::Value TrunkLink::statusJson(void) const
entry["lon"] = n.lon;
}
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
// 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
// periodic node-list push.
entry["isTalker"] =
(TGHandler::instance()->trunkTalkerForTG(n.tg) == n.callsign);
nodes_arr.append(entry);
}
obj["nodes"] = nodes_arr;
@@ -1782,6 +1835,8 @@ void TrunkLink::handleMsgTrunkNodeList(std::istream& is)
e.lat = 0.0f;
e.lon = 0.0f;
}
e.status = n.status;
sanitizeJsonStrings(e.status);
sanitized.push_back(std::move(e));
}
if (dropped > 0)
+46 -1
View File
@@ -106,6 +106,46 @@ std::string sanitizeText(const std::string& in, size_t max_bytes)
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);
}
}
}
} /* anonymous namespace */
@@ -340,7 +380,8 @@ Json::Value TwinLink::statusJson(void) const
Json::Value nodes_arr(Json::arrayValue);
for (const auto& n : m_partner_nodes)
{
Json::Value entry(Json::objectValue);
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)
@@ -349,6 +390,8 @@ Json::Value TwinLink::statusJson(void) const
entry["lon"] = n.lon;
}
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
entry["isTalker"] =
(TGHandler::instance()->trunkTalkerForTG(n.tg) == n.callsign);
nodes_arr.append(entry);
}
obj["nodes"] = nodes_arr;
@@ -646,6 +689,8 @@ void TwinLink::handleMsgTrunkNodeList(std::istream& is)
e.lat = n.lat;
e.lon = n.lon;
}
e.status = n.status;
sanitizeJsonStrings(e.status);
sanitized.push_back(std::move(e));
}
if (dropped > 0)
+15
View File
@@ -1868,6 +1868,21 @@ class TestTrunkIntegration(unittest.TestCase):
msg=f"{CLIENT_CALLSIGN} did not appear in {peer}'s "
f"/status.trunks.{section}.nodes after login on "
f"{self.PRIMARY}")
# Rich-roster check: the partner-node entry must carry an
# isTalker flag derived from the live trunk-talker map
# (false here — client is idle). This exercises the wire
# extension to MsgTrunkNodeList type 121 and the receive-side
# join with TGHandler::trunkTalkerForTG.
status = get_status(*_http(peer))
trunk = status.get("trunks", {}).get(section, {})
entry = next(n for n in trunk.get("nodes", [])
if n.get("callsign") == CLIENT_CALLSIGN)
self.assertIn("isTalker", entry,
"partner-node entry must expose isTalker for parity "
"with local-client /status entries")
self.assertFalse(entry["isTalker"],
"idle client should report isTalker=false")
finally:
client.close()