redis: mirror peer node lists + sanitize trunk-received strings

Peer node lists (MsgTrunkNodeList, type 121) now propagate into Redis
alongside the existing MQTT publish, so dashboards reading Redis see a
complete view of local + peer rosters. Each remote entry is stored as
live:peer_node:<peer_id>:<callsign> with 60s TTL; a per-peer cache
diffs incoming snapshots so dropped callsigns are DEL'd, and a full
trunk-down deletes all of that peer's entries.

All untrusted strings arriving via the trunk (peer_id from the hello,
plus callsign/qth/lat/lon in node lists) are now sanitized at receive:
control chars + ':' stripped, length bounded (32 callsign, 64 peer_id
and qth), non-finite and out-of-range coordinates cleared. Entries
whose callsign becomes empty after sanitization are dropped.

Also reorders TrunkLink in/outbound onDisconnected so the state-change
notification fires after the per-direction state is cleared, letting
consumers that inspect isActive() (like the Redis peer-node cleanup)
see the correct post-disconnect state.

Adds RedisPeerNodeTest (3 cases: populate+diff, sanitization, trunk-
down cleanup) and a build_node_list wire helper in test_trunk.py.
Exposes the trunk port in docker-compose.redis.yml so the host can
inject trunk frames against the r1 test reflector.
This commit is contained in:
Audric committed 2026-04-16 21:25:37 +02:00
1 parent 0700e01453
commit 7b95d0d2ce
10 files changed
+399 -9

No files matched your search

+45
View File
@@ -3034,6 +3034,27 @@ void Reflector::onPeerNodeList(const std::string& peer_id,
{
m_mqtt->publishPeerNodes(peer_id, nodes);
}
if (m_redis != nullptr && !peer_id.empty())
{
std::set<std::string> seen;
for (const auto& n : nodes)
{
if (n.callsign.empty()) continue;
seen.insert(n.callsign);
m_redis->pushPeerNode(peer_id, n.callsign, n.tg,
n.lat, n.lon, n.qth_name);
}
auto& prev = m_peer_node_cache[peer_id];
for (const std::string& cs : prev)
{
if (seen.find(cs) == seen.end())
{
m_redis->clearPeerNode(peer_id, cs);
}
}
prev = std::move(seen);
}
} /* Reflector::onPeerNodeList */
@@ -3059,6 +3080,30 @@ void Reflector::onTrunkStateChanged(const std::string& section,
{
m_redis->pushLiveTrunk(section, up ? "up" : "down", peer_id);
}
// When a trunk link is fully down (both directions), clear any node
// entries we were mirroring from this peer into Redis. Keeps Redis in
// sync with the fact that we can no longer observe the peer's roster.
if (!up && m_redis != nullptr && !peer_id.empty())
{
TrunkLink* link = nullptr;
for (auto* l : m_trunk_links)
{
if (l->section() == section) { link = l; break; }
}
if (link == nullptr || !link->isActive())
{
auto it = m_peer_node_cache.find(peer_id);
if (it != m_peer_node_cache.end())
{
for (const std::string& cs : it->second)
{
m_redis->clearPeerNode(peer_id, cs);
}
m_peer_node_cache.erase(it);
}
}
}
} /* Reflector::onTrunkStateChanged */