From 81672bae2388b4a757f8e0c0e810697d3f92250a Mon Sep 17 00:00:00 2001 From: Audric Date: Tue, 28 Apr 2026 19:18:25 +0200 Subject: [PATCH] feat(satellite): add MsgPeerClient* send/receive on SatelliteClient Satellite-side endpoint gains the symmetric send/receive paths so that satellite-local client events propagate to the parent and the parent's client events arrive at the satellite's broker. --- src/svxlink/reflector/SatelliteClient.cpp | 140 ++++++++++++++++++++++ src/svxlink/reflector/SatelliteClient.h | 12 ++ 2 files changed, 152 insertions(+) diff --git a/src/svxlink/reflector/SatelliteClient.cpp b/src/svxlink/reflector/SatelliteClient.cpp index 7af43dd..c093b9d 100644 --- a/src/svxlink/reflector/SatelliteClient.cpp +++ b/src/svxlink/reflector/SatelliteClient.cpp @@ -271,6 +271,18 @@ void SatelliteClient::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: break; } @@ -444,6 +456,134 @@ void SatelliteClient::sendMsg(const ReflectorMsg& msg) } /* SatelliteClient::sendMsg */ +void SatelliteClient::sendClientConnected(const std::string& callsign, + uint32_t tg, + const std::string& ip) +{ + if (!m_con.isConnected() || !m_hello_received) return; + // No TG filter on satellite->parent direction (parent doesn't filter + // satellite-side clients today; if it ever advertises one, the same + // filterPassesTg() pattern from SatelliteLink applies). + sendMsg(MsgPeerClientConnected(callsign, tg, ip)); +} /* SatelliteClient::sendClientConnected */ + + +void SatelliteClient::sendClientDisconnected(const std::string& callsign) +{ + if (!m_con.isConnected() || !m_hello_received) return; + sendMsg(MsgPeerClientDisconnected(callsign)); +} /* SatelliteClient::sendClientDisconnected */ + + +void SatelliteClient::sendClientRx(const std::string& callsign, + const std::string& rx_json) +{ + if (!m_con.isConnected() || !m_hello_received) return; + sendMsg(MsgPeerClientRx(callsign, rx_json)); +} /* SatelliteClient::sendClientRx */ + + +void SatelliteClient::sendClientStatus(const std::string& callsign, + const std::string& status_json) +{ + if (!m_con.isConnected() || !m_hello_received) return; + sendMsg(MsgPeerClientStatus(callsign, status_json)); +} /* SatelliteClient::sendClientStatus */ + + +void SatelliteClient::handleMsgPeerClientConnected(std::istream& is) +{ + MsgPeerClientConnected msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientConnected from parent '", + m_parent_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_parent_id, msg.callsign(), "connected", payload, false); + } +} /* SatelliteClient::handleMsgPeerClientConnected */ + + +void SatelliteClient::handleMsgPeerClientDisconnected(std::istream& is) +{ + MsgPeerClientDisconnected msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientDisconnected from parent '", + m_parent_id, "'"); + return; + } + Json::Value payload(Json::objectValue); + if (m_reflector->mqtt() != nullptr) + { + m_reflector->mqtt()->publishPeerClientEvent( + m_parent_id, msg.callsign(), "disconnected", payload, false); + } +} /* SatelliteClient::handleMsgPeerClientDisconnected */ + + +void SatelliteClient::handleMsgPeerClientRx(std::istream& is) +{ + MsgPeerClientRx msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientRx from parent '", m_parent_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_parent_id, msg.callsign(), "rx", rx_json, true); // retained + } +} /* SatelliteClient::handleMsgPeerClientRx */ + + +void SatelliteClient::handleMsgPeerClientStatus(std::istream& is) +{ + MsgPeerClientStatus msg; + if (!msg.unpack(is)) + { + geulog::error("satellite", + "Failed to unpack MsgPeerClientStatus from parent '", + m_parent_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_parent_id, msg.callsign(), "status", status_json, true); // retained + } +} /* SatelliteClient::handleMsgPeerClientStatus */ + + void SatelliteClient::heartbeatTick(Async::Timer* t) { if (--m_hb_tx_cnt == 0) diff --git a/src/svxlink/reflector/SatelliteClient.h b/src/svxlink/reflector/SatelliteClient.h index 8820795..72bb8bf 100644 --- a/src/svxlink/reflector/SatelliteClient.h +++ b/src/svxlink/reflector/SatelliteClient.h @@ -48,6 +48,14 @@ class SatelliteClient : public sigc::trackable void sendNodeList( const std::vector& nodes); + 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 parent's combined-view roster, surfaced // by Reflector::statusJson under /status.parent.nodes. const std::vector& parentNodes(void) const @@ -96,6 +104,10 @@ class SatelliteClient : public sigc::trackable void handleMsgPeerFlush(std::istream& is); void handleMsgPeerHeartbeat(void); 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); void sendMsg(const ReflectorMsg& msg); void sendFilter(void); void heartbeatTick(Async::Timer* t);