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/<sat_id>/client/<call>/<event>, retained for rx/status).

A Reflector::mqtt() accessor was added to expose m_mqtt to link
classes for receive-side republishing.
This commit is contained in:
Audric committed 2026-04-28 19:07:56 +02:00
1 parent 37a6a11548
commit 11b1a7b518
3 files changed
+156

No files matched your search

+1
View File
@@ -265,6 +265,7 @@ class Reflector : public sigc::trackable
uint32_t tg); uint32_t tg);
RedisStore* redisStore(void) const { return m_redis; } RedisStore* redisStore(void) const { return m_redis; }
MqttPublisher* mqtt(void) const { return m_mqtt; }
// Callbacks for SatelliteLink to forward satellite events to trunk peers // Callbacks for SatelliteLink to forward satellite events to trunk peers
void forwardSatelliteAudioToTrunks(uint32_t tg, void forwardSatelliteAudioToTrunks(uint32_t tg,
+142
View File
@@ -251,6 +251,18 @@ void SatelliteLink::onFrameReceived(FramedTcpConnection* con,
case MsgPeerNodeList::TYPE: case MsgPeerNodeList::TYPE:
handleMsgPeerNodeList(ss); handleMsgPeerNodeList(ss);
break; 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: default:
geulog::warn("satellite", "Unknown message type=", header.type()); geulog::warn("satellite", "Unknown message type=", header.type());
break; break;
@@ -526,3 +538,133 @@ void SatelliteLink::sendNodeList(
} }
sendMsg(MsgPeerNodeList(filtered)); sendMsg(MsgPeerNodeList(filtered));
} /* SatelliteLink::sendNodeList */ } /* 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<Json::UInt>(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 */
+13
View File
@@ -62,6 +62,15 @@ class SatelliteLink : public sigc::trackable
void sendNodeList( void sendNodeList(
const std::vector<MsgPeerNodeList::NodeEntry>& nodes); const std::vector<MsgPeerNodeList::NodeEntry>& 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 // Read-only access to the satellite-supplied roster (this satellite's
// local clients), already sanitised and stamped with sat_id = // local clients), already sanitised and stamped with sat_id =
// satelliteId(). Used by Reflector to merge into the parent's // satelliteId(). Used by Reflector to merge into the parent's
@@ -102,6 +111,10 @@ class SatelliteLink : public sigc::trackable
void handleMsgPeerHeartbeat(void); void handleMsgPeerHeartbeat(void);
void handleMsgPeerFilter(std::istream& is); void handleMsgPeerFilter(std::istream& is);
void handleMsgPeerNodeList(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; bool filterPassesTg(uint32_t tg) const;
void sendMsg(const ReflectorMsg& msg); void sendMsg(const ReflectorMsg& msg);
void heartbeatTick(Async::Timer* t); void heartbeatTick(Async::Timer* t);