Files
GeuReflector/src/svxlink/reflector/SatelliteLink.h
T
Audric 11b1a7b518 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.
2026-04-28 19:07:56 +02:00

124 lines
4.9 KiB
C++

#ifndef SATELLITE_LINK_INCLUDED
#define SATELLITE_LINK_INCLUDED
#include <set>
#include <string>
#include <vector>
#include <sigc++/sigc++.h>
#include <json/json.h>
#include <AsyncFramedTcpConnection.h>
#include <AsyncTimer.h>
#include "TgFilter.h"
#include "ReflectorMsg.h"
class Reflector;
/**
@brief Handles one inbound satellite connection on the parent reflector
A SatelliteLink is created for each satellite that connects to the parent's
satellite port. By default it relays ALL TGs bidirectionally. When the
satellite sends a MsgPeerFilter (type 122), the parent applies the filter
to outbound traffic — only matching TGs are forwarded to this satellite.
The parent always wins talker arbitration over satellites.
*/
class SatelliteLink : public sigc::trackable
{
public:
SatelliteLink(Reflector* reflector, Async::FramedTcpConnection* con,
const std::string& secret);
~SatelliteLink(void);
bool isAuthenticated(void) const { return m_hello_received; }
const std::string& satelliteId(void) const { return m_satellite_id; }
Json::Value statusJson(void) const;
/**
* Emitted when the satellite link has failed (heartbeat timeout).
* The Reflector must handle cleanup — the SatelliteLink stops its own
* timer but does NOT call m_con->disconnect() itself.
*/
sigc::signal<void, SatelliteLink*> linkFailed;
/**
* Emitted whenever the per-satellite status (id, authentication,
* active TGs) changes. Reflector uses this to refresh the satellite's
* Redis snapshot. Carries `this`; ignore if satelliteId() is empty
* (hello not yet received).
*/
sigc::signal<void, SatelliteLink*> statusChanged;
// Events from local clients or trunk peers → send down to satellite
void onParentTalkerStart(uint32_t tg, const std::string& callsign);
void onParentTalkerStop(uint32_t tg);
void onParentAudio(uint32_t tg, const std::vector<uint8_t>& audio);
void onParentFlush(uint32_t tg);
// Send a node list down to the satellite. Caller passes the combined
// parent-known roster minus this satellite's own contribution; this
// method additionally drops entries whose TG falls outside the
// satellite's announced filter (if any).
void sendNodeList(
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
// local clients), already sanitised and stamped with sat_id =
// satelliteId(). Used by Reflector to merge into the parent's
// outbound advertisements.
const std::vector<MsgPeerNodeList::NodeEntry>& partnerNodes(void) const
{
return m_partner_nodes;
}
private:
static const unsigned HEARTBEAT_TX_CNT_RESET = 10;
static const unsigned HEARTBEAT_RX_CNT_RESET = 15;
Reflector* m_reflector;
Async::FramedTcpConnection* m_con;
std::string m_secret;
std::string m_satellite_id;
bool m_hello_received;
Async::Timer m_heartbeat_timer;
unsigned m_hb_tx_cnt;
unsigned m_hb_rx_cnt;
std::set<uint32_t> m_sat_active_tgs;
TgFilter m_tg_filter;
// Roster of clients attached to this satellite, learned via
// MsgPeerNodeList from the satellite. Each entry carries
// sat_id == m_satellite_id (stamped on ingest) so the Reflector can
// merge it into outbound trunk/twin/sibling-sat lists with correct
// attribution.
std::vector<MsgPeerNodeList::NodeEntry> m_partner_nodes;
void onFrameReceived(Async::FramedTcpConnection* con,
std::vector<uint8_t>& data);
void handleMsgPeerHello(std::istream& is);
void handleMsgPeerTalkerStart(std::istream& is);
void handleMsgPeerTalkerStop(std::istream& is);
void handleMsgPeerAudio(std::istream& is);
void handleMsgPeerFlush(std::istream& is);
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);
};
#endif /* SATELLITE_LINK_INCLUDED */