From 11b1a7b518bd629f1347ee6d2f52d8109f508c3f Mon Sep 17 00:00:00 2001 From: Audric Date: Tue, 28 Apr 2026 18:59:15 +0200 Subject: [PATCH] feat(satellite): add MsgPeerClient* send/receive on SatelliteLink Parent-side of the satellite link gains sendClient* (with TG-filter on connect) and handleMsgPeerClient* (republishing to the local MQTT broker as peer//client//, retained for rx/status). A Reflector::mqtt() accessor was added to expose m_mqtt to link classes for receive-side republishing. --- src/svxlink/reflector/Reflector.h | 1 + src/svxlink/reflector/SatelliteLink.cpp | 142 ++++++++++++++++++++++++ src/svxlink/reflector/SatelliteLink.h | 13 +++ 3 files changed, 156 insertions(+) diff --git a/src/svxlink/reflector/Reflector.h b/src/svxlink/reflector/Reflector.h index f24a0fe..a2dba1f 100644 --- a/src/svxlink/reflector/Reflector.h +++ b/src/svxlink/reflector/Reflector.h @@ -265,6 +265,7 @@ class Reflector : public sigc::trackable uint32_t tg); RedisStore* redisStore(void) const { return m_redis; } + MqttPublisher* mqtt(void) const { return m_mqtt; } // Callbacks for SatelliteLink to forward satellite events to trunk peers void forwardSatelliteAudioToTrunks(uint32_t tg, diff --git a/src/svxlink/reflector/SatelliteLink.cpp b/src/svxlink/reflector/SatelliteLink.cpp index 2e5c422..3e7fa8f 100644 --- a/src/svxlink/reflector/SatelliteLink.cpp +++ b/src/svxlink/reflector/SatelliteLink.cpp @@ -251,6 +251,18 @@ void SatelliteLink::onFrameReceived(FramedTcpConnection* con, case MsgPeerNodeList::TYPE: handleMsgPeerNodeList(ss); break; + case MsgPeerClientConnected::TYPE: + handleMsgPeerClientConnected(ss); + break; + case MsgPeerClientDisconnected::TYPE: + handleMsgPeerClientDisconnected(ss); + break; + case MsgPeerClientRx::TYPE: + handleMsgPeerClientRx(ss); + break; + case MsgPeerClientStatus::TYPE: + handleMsgPeerClientStatus(ss); + break; default: geulog::warn("satellite", "Unknown message type=", header.type()); break; @@ -526,3 +538,133 @@ void SatelliteLink::sendNodeList( } sendMsg(MsgPeerNodeList(filtered)); } /* SatelliteLink::sendNodeList */ + + +void SatelliteLink::sendClientConnected(const std::string& callsign, + uint32_t tg, + const std::string& ip) +{ + if (!m_hello_received) return; + // TG filter applied at sender — drop if the client's TG is outside + // this satellite's filter. + if (!filterPassesTg(tg)) return; + sendMsg(MsgPeerClientConnected(callsign, tg, ip)); +} /* SatelliteLink::sendClientConnected */ + + +void SatelliteLink::sendClientDisconnected(const std::string& callsign) +{ + if (!m_hello_received) return; + // No TG in this message — filter is applied at the caller + // (Reflector::fanoutClientDisconnected) using current-TG lookup. + sendMsg(MsgPeerClientDisconnected(callsign)); +} /* SatelliteLink::sendClientDisconnected */ + + +void SatelliteLink::sendClientRx(const std::string& callsign, + const std::string& rx_json) +{ + if (!m_hello_received) return; + sendMsg(MsgPeerClientRx(callsign, rx_json)); +} /* SatelliteLink::sendClientRx */ + + +void SatelliteLink::sendClientStatus(const std::string& callsign, + const std::string& status_json) +{ + if (!m_hello_received) return; + sendMsg(MsgPeerClientStatus(callsign, status_json)); +} /* SatelliteLink::sendClientStatus */ + + +void SatelliteLink::handleMsgPeerClientConnected(std::istream& is) +{ + MsgPeerClientConnected msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientConnected from '", + m_satellite_id, "'"); + return; + } + Json::Value payload; + payload["tg"] = static_cast(msg.tg()); + payload["ip"] = msg.ip(); + if (m_reflector->mqtt() != nullptr) + { + m_reflector->mqtt()->publishPeerClientEvent( + m_satellite_id, msg.callsign(), "connected", payload, false); + } +} /* SatelliteLink::handleMsgPeerClientConnected */ + + +void SatelliteLink::handleMsgPeerClientDisconnected(std::istream& is) +{ + MsgPeerClientDisconnected msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientDisconnected from '", + m_satellite_id, "'"); + return; + } + Json::Value payload(Json::objectValue); + if (m_reflector->mqtt() != nullptr) + { + m_reflector->mqtt()->publishPeerClientEvent( + m_satellite_id, msg.callsign(), "disconnected", payload, false); + } +} /* SatelliteLink::handleMsgPeerClientDisconnected */ + + +void SatelliteLink::handleMsgPeerClientRx(std::istream& is) +{ + MsgPeerClientRx msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientRx from '", m_satellite_id, "'"); + return; + } + if (msg.rxJson().size() > 65536u) return; + Json::Value rx_json; + std::istringstream ss(msg.rxJson()); + Json::CharReaderBuilder rb; + std::string err; + if (!Json::parseFromStream(rb, ss, &rx_json, &err)) + { + return; + } + if (m_reflector->mqtt() != nullptr) + { + m_reflector->mqtt()->publishPeerClientEvent( + m_satellite_id, msg.callsign(), "rx", rx_json, true); + } +} /* SatelliteLink::handleMsgPeerClientRx */ + + +void SatelliteLink::handleMsgPeerClientStatus(std::istream& is) +{ + MsgPeerClientStatus msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientStatus from '", + m_satellite_id, "'"); + return; + } + if (msg.statusJson().size() > 65536u) return; + Json::Value status_json; + std::istringstream ss(msg.statusJson()); + Json::CharReaderBuilder rb; + std::string err; + if (!Json::parseFromStream(rb, ss, &status_json, &err)) + { + return; + } + if (m_reflector->mqtt() != nullptr) + { + m_reflector->mqtt()->publishPeerClientEvent( + m_satellite_id, msg.callsign(), "status", status_json, true); + } +} /* SatelliteLink::handleMsgPeerClientStatus */ diff --git a/src/svxlink/reflector/SatelliteLink.h b/src/svxlink/reflector/SatelliteLink.h index 7178cc1..42a21bc 100644 --- a/src/svxlink/reflector/SatelliteLink.h +++ b/src/svxlink/reflector/SatelliteLink.h @@ -62,6 +62,15 @@ class SatelliteLink : public sigc::trackable void sendNodeList( const std::vector& nodes); + // Per-client liveness events → send down to satellite. + void sendClientConnected(const std::string& callsign, uint32_t tg, + const std::string& ip); + void sendClientDisconnected(const std::string& callsign); + void sendClientRx(const std::string& callsign, + const std::string& rx_json); + void sendClientStatus(const std::string& callsign, + const std::string& status_json); + // Read-only access to the satellite-supplied roster (this satellite's // local clients), already sanitised and stamped with sat_id = // satelliteId(). Used by Reflector to merge into the parent's @@ -102,6 +111,10 @@ class SatelliteLink : public sigc::trackable void handleMsgPeerHeartbeat(void); void handleMsgPeerFilter(std::istream& is); void handleMsgPeerNodeList(std::istream& is); + void handleMsgPeerClientConnected(std::istream& is); + void handleMsgPeerClientDisconnected(std::istream& is); + void handleMsgPeerClientRx(std::istream& is); + void handleMsgPeerClientStatus(std::istream& is); bool filterPassesTg(uint32_t tg) const; void sendMsg(const ReflectorMsg& msg); void heartbeatTick(Async::Timer* t);