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

+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)