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:
1 parent
0700e01453
commit
7b95d0d2ce
10 files changed
+399
-9
No files matched your search
@@ -314,6 +314,43 @@ void RedisStore::clearLiveClient(const std::string& callsign) {
|
||||
m_live_queue->push(std::move(op));
|
||||
}
|
||||
|
||||
void RedisStore::pushPeerNode(const std::string& peer_id,
|
||||
const std::string& callsign,
|
||||
uint32_t tg,
|
||||
float lat, float lon,
|
||||
const std::string& qth_name) {
|
||||
if (!m_live_queue) return;
|
||||
RedisLiveQueue::Op op;
|
||||
op.op = RedisLiveQueue::OpType::HSET;
|
||||
op.key = keyFor("live:peer_node:" + peer_id + ":" + callsign);
|
||||
m_live_keys.insert(op.key);
|
||||
op.fields = {
|
||||
{"peer_id", peer_id},
|
||||
{"callsign", callsign},
|
||||
{"tg", std::to_string(tg)},
|
||||
{"updated_at", std::to_string(std::time(nullptr))}
|
||||
};
|
||||
if (lat != 0.0f || lon != 0.0f) {
|
||||
op.fields.emplace_back("lat", std::to_string(lat));
|
||||
op.fields.emplace_back("lon", std::to_string(lon));
|
||||
}
|
||||
if (!qth_name.empty()) {
|
||||
op.fields.emplace_back("qth_name", qth_name);
|
||||
}
|
||||
op.ttl_s = 60;
|
||||
m_live_queue->push(std::move(op));
|
||||
}
|
||||
|
||||
void RedisStore::clearPeerNode(const std::string& peer_id,
|
||||
const std::string& callsign) {
|
||||
if (!m_live_queue) return;
|
||||
RedisLiveQueue::Op op;
|
||||
op.op = RedisLiveQueue::OpType::DEL;
|
||||
op.key = keyFor("live:peer_node:" + peer_id + ":" + callsign);
|
||||
m_live_keys.erase(op.key);
|
||||
m_live_queue->push(std::move(op));
|
||||
}
|
||||
|
||||
void RedisStore::pushLiveTrunk(const std::string& section,
|
||||
const std::string& state,
|
||||
const std::string& peer_id) {
|
||||
|
||||
Reference in new issue
Block a user