Implement satellite reflectors
Satellite reflectors are lightweight relay instances that connect to a parent reflector instead of joining the full trunk mesh. Clients connect to the satellite normally; it relays all TGs bidirectionally to the parent. The parent forwards satellite events to local clients, trunk peers, and other satellites. New classes: - SatelliteLink: parent-side handler for each inbound satellite connection (HMAC auth, heartbeat, all-TG relay) - SatelliteClient: satellite-side outbound connection to parent Wire protocol: MsgTrunkHello gains m_role field (ROLE_PEER=0, ROLE_SATELLITE=1) to distinguish satellite handshakes. Config: - Parent: [SATELLITE] section with LISTEN_PORT and SECRET - Satellite: SATELLITE_OF, SATELLITE_PORT, SATELLITE_SECRET in [GLOBAL] HTTP /config endpoint now shows mode (reflector/satellite), satellite_server config on parents, and satellite connection info. Docs updated: README, DEPLOYMENT_ITALY, Italian translation.
This commit is contained in:
1 parent
166e57f445
commit
551cfa70cd
13 files changed
+1159
-20
No files matched your search
@@ -47,8 +47,13 @@ automatically.
|
||||
- **Independent talker arbitration** — each reflector arbitrates its own clients;
|
||||
the trunk adds a tie-breaking layer (random priority nonce) for simultaneous
|
||||
claims
|
||||
- **HTTP `/status` endpoint** — existing JSON status now includes a `trunks`
|
||||
object with per-link state and active talkers
|
||||
- **Cluster TGs** — BrandMeister-style nationwide talk groups that are broadcast
|
||||
to all trunk peers regardless of prefix ownership
|
||||
- **Satellite reflectors** — lightweight relay instances that connect to a parent
|
||||
reflector instead of joining the full mesh, reducing configuration overhead for
|
||||
large deployments
|
||||
- **HTTP `/status` and `/config` endpoints** — JSON status with trunk state,
|
||||
active talkers, satellite connections, and static configuration
|
||||
- SvxLink client nodes are **unmodified** — they connect to their local
|
||||
reflector as normal and are unaware of the trunk
|
||||
|
||||
@@ -181,6 +186,50 @@ REMOTE_PREFIX=2
|
||||
|
||||
Both sides of each trunk must point at each other and share the same `SECRET`.
|
||||
|
||||
### Satellite reflectors
|
||||
|
||||
A satellite is a lightweight reflector that connects to a parent reflector
|
||||
instead of joining the trunk mesh. Clients connect to the satellite normally;
|
||||
it relays everything to the parent. The parent is unchanged — it still
|
||||
participates in the trunk mesh as before.
|
||||
|
||||
```
|
||||
┌──── Full mesh (unchanged) ────┐
|
||||
│ │
|
||||
┌─────┴─────┐ ┌─────┴─────┐
|
||||
│ Refl. 01 │◄── trunk ──────►│ Refl. 02 │
|
||||
└─────┬─────┘ └───────────┘
|
||||
┌────┼────┐
|
||||
▼ ▼ ▼
|
||||
Sat A Sat B Sat C ← satellites of Reflector 01
|
||||
```
|
||||
|
||||
**Parent side** — add a `[SATELLITE]` section to accept inbound satellites:
|
||||
|
||||
```ini
|
||||
[SATELLITE]
|
||||
LISTEN_PORT=5303
|
||||
SECRET=regional_satellite_secret
|
||||
```
|
||||
|
||||
**Satellite side** — set `SATELLITE_OF` in `[GLOBAL]` instead of
|
||||
`LOCAL_PREFIX` and `[TRUNK_x]` sections:
|
||||
|
||||
```ini
|
||||
[GLOBAL]
|
||||
SATELLITE_OF=reflector-01.example.com
|
||||
SATELLITE_PORT=5303
|
||||
SATELLITE_SECRET=regional_satellite_secret
|
||||
SATELLITE_ID=my-satellite
|
||||
```
|
||||
|
||||
A satellite does not set `LOCAL_PREFIX`, `REMOTE_PREFIX`, or any `[TRUNK_x]`
|
||||
sections. It inherits its parent's identity. Remote reflectors in the mesh see
|
||||
satellite clients as if they were connected directly to the parent.
|
||||
|
||||
Port `5303` is the default satellite port (separate from client port `5300` and
|
||||
trunk port `5302`).
|
||||
|
||||
---
|
||||
|
||||
## HTTP Status
|
||||
@@ -207,12 +256,20 @@ Returns nodes, trunk connection state, and active talkers:
|
||||
"25": "SM0ABC"
|
||||
}
|
||||
}
|
||||
},
|
||||
"satellites": {
|
||||
"my-satellite": {
|
||||
"id": "my-satellite",
|
||||
"authenticated": true,
|
||||
"active_tgs": [1, 100]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`active_talkers` lists TGs with an active remote talker at query time (both
|
||||
prefix-based and cluster TGs).
|
||||
prefix-based and cluster TGs). `satellites` appears only when satellites are
|
||||
connected.
|
||||
|
||||
### `GET /config` — static configuration
|
||||
|
||||
@@ -220,6 +277,7 @@ Returns the reflector's own configuration, useful for dashboards:
|
||||
|
||||
```json
|
||||
{
|
||||
"mode": "reflector",
|
||||
"local_prefix": ["1"],
|
||||
"cluster_tgs": [222, 2221, 91],
|
||||
"listen_port": "5300",
|
||||
@@ -230,6 +288,24 @@ Returns the reflector's own configuration, useful for dashboards:
|
||||
"port": 5302,
|
||||
"remote_prefix": ["2"]
|
||||
}
|
||||
},
|
||||
"satellite_server": {
|
||||
"listen_port": "5303",
|
||||
"connected_count": 2
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When running in satellite mode:
|
||||
|
||||
```json
|
||||
{
|
||||
"mode": "satellite",
|
||||
"listen_port": "5300",
|
||||
"satellite": {
|
||||
"parent_host": "reflector-01.example.com",
|
||||
"parent_port": "5303",
|
||||
"id": "my-satellite"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -294,6 +370,8 @@ restart.
|
||||
deployment example for Italy (20 regions, full mesh)
|
||||
- [`docs/DEPLOYMENT_ITALY_IT.md`](docs/DEPLOYMENT_ITALY_IT.md) — same document
|
||||
in Italian
|
||||
- [`docs/DESIGN_SATELLITE_AND_CLUSTER.md`](docs/DESIGN_SATELLITE_AND_CLUSTER.md) — design
|
||||
rationale for satellite reflectors and cluster TGs
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -289,6 +289,36 @@ licensed operators active at any given time.
|
||||
|
||||
---
|
||||
|
||||
## Satellite reflectors (optional)
|
||||
|
||||
Larger regions may want to run additional reflector instances as satellites
|
||||
(e.g. one per province) to distribute the client load without adding more trunk
|
||||
mesh connections. A satellite connects to its regional reflector and relays all
|
||||
traffic — remote reflectors see satellite clients as if they were connected
|
||||
directly to the regional reflector.
|
||||
|
||||
**Regional reflector** (e.g. Lazio) — add a `[SATELLITE]` section:
|
||||
```ini
|
||||
[SATELLITE]
|
||||
LISTEN_PORT=5303
|
||||
SECRET=lazio_satellite_secret
|
||||
```
|
||||
|
||||
**Satellite** (e.g. Roma province):
|
||||
```ini
|
||||
[GLOBAL]
|
||||
SATELLITE_OF=svxref-lazio.example.it
|
||||
SATELLITE_PORT=5303
|
||||
SATELLITE_SECRET=lazio_satellite_secret
|
||||
SATELLITE_ID=sat-roma
|
||||
```
|
||||
|
||||
The satellite does not set `LOCAL_PREFIX`, `REMOTE_PREFIX`, or any `[TRUNK_xx]`
|
||||
sections. It only needs `LISTEN_PORT=5300` for its local SvxLink clients. Also
|
||||
open port `5303` inbound on the regional reflector firewall.
|
||||
|
||||
---
|
||||
|
||||
## Per-region config checklist
|
||||
|
||||
1. Set `LOCAL_PREFIX` to the 2-digit code from the table above.
|
||||
@@ -296,4 +326,5 @@ licensed operators active at any given time.
|
||||
3. Use the same `SECRET` value as the matching section on the peer — mismatched
|
||||
secrets will prevent the trunk from connecting.
|
||||
4. Open TCP port `5302` inbound in the firewall (trunk) and `5300` inbound (clients).
|
||||
5. Ensure `HOST` resolves to the peer's public IP from the server's network.
|
||||
5. If accepting satellites, also open TCP port `5303` inbound.
|
||||
6. Ensure `HOST` resolves to the peer's public IP from the server's network.
|
||||
@@ -296,6 +296,37 @@ il vero limite pratico è il numero di operatori patentati attivi in un dato mom
|
||||
|
||||
---
|
||||
|
||||
## Reflector satellite (opzionale)
|
||||
|
||||
Le regioni più grandi possono eseguire istanze aggiuntive come satellite
|
||||
(ad esempio una per provincia) per distribuire il carico client senza aggiungere
|
||||
ulteriori connessioni trunk. Un satellite si collega al proprio reflector
|
||||
regionale e inoltra tutto il traffico — i reflector remoti vedono i client
|
||||
satellite come se fossero connessi direttamente al reflector regionale.
|
||||
|
||||
**Reflector regionale** (es. Lazio) — aggiungere una sezione `[SATELLITE]`:
|
||||
```ini
|
||||
[SATELLITE]
|
||||
LISTEN_PORT=5303
|
||||
SECRET=lazio_satellite_secret
|
||||
```
|
||||
|
||||
**Satellite** (es. provincia di Roma):
|
||||
```ini
|
||||
[GLOBAL]
|
||||
SATELLITE_OF=svxref-lazio.example.it
|
||||
SATELLITE_PORT=5303
|
||||
SATELLITE_SECRET=lazio_satellite_secret
|
||||
SATELLITE_ID=sat-roma
|
||||
```
|
||||
|
||||
Il satellite non imposta `LOCAL_PREFIX`, `REMOTE_PREFIX` o alcuna sezione
|
||||
`[TRUNK_xx]`. Necessita solo di `LISTEN_PORT=5300` per i propri client SvxLink
|
||||
locali. Aprire anche la porta `5303` in ingresso sul firewall del reflector
|
||||
regionale.
|
||||
|
||||
---
|
||||
|
||||
## Lista di controllo per ogni regione
|
||||
|
||||
1. Impostare `LOCAL_PREFIX` al codice a 2 cifre dalla tabella sopra.
|
||||
@@ -303,4 +334,5 @@ il vero limite pratico è il numero di operatori patentati attivi in un dato mom
|
||||
3. Usare lo stesso valore di `SECRET` della sezione corrispondente sul peer — secret
|
||||
non corrispondenti impediranno la connessione del trunk.
|
||||
4. Aprire la porta TCP `5302` in ingresso nel firewall (trunk) e la porta `5300` (client).
|
||||
5. Verificare che `HOST` risolva all'IP pubblico del peer dalla rete del server.
|
||||
5. Se si accettano satellite, aprire anche la porta TCP `5303` in ingresso.
|
||||
6. Verificare che `HOST` risolva all'IP pubblico del peer dalla rete del server.
|
||||
@@ -25,6 +25,7 @@ set(LIBS asynccpp asyncaudio asynccore svxmisc ${LIBS})
|
||||
# Build the executable
|
||||
add_executable(svxreflector
|
||||
svxreflector.cpp Reflector.cpp ReflectorClient.cpp TGHandler.cpp TrunkLink.cpp
|
||||
SatelliteLink.cpp SatelliteClient.cpp
|
||||
)
|
||||
target_link_libraries(svxreflector ${LIBS})
|
||||
set_target_properties(svxreflector PROPERTIES
|
||||
|
||||
@@ -287,6 +287,15 @@ Reflector::~Reflector(void)
|
||||
delete link;
|
||||
}
|
||||
m_trunk_links.clear();
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
delete kv.second;
|
||||
}
|
||||
m_satellite_con_map.clear();
|
||||
delete m_sat_srv;
|
||||
m_sat_srv = nullptr;
|
||||
delete m_satellite_client;
|
||||
m_satellite_client = nullptr;
|
||||
m_client_con_map.clear();
|
||||
ReflectorClient::cleanup();
|
||||
delete TGHandler::instance();
|
||||
@@ -417,7 +426,25 @@ bool Reflector::initialize(Async::Config &cfg)
|
||||
}
|
||||
}
|
||||
|
||||
// Satellite mode: connect to parent instead of joining the trunk mesh
|
||||
std::string satellite_of;
|
||||
if (cfg.getValue("GLOBAL", "SATELLITE_OF", satellite_of) &&
|
||||
!satellite_of.empty())
|
||||
{
|
||||
m_is_satellite = true;
|
||||
m_satellite_client = new SatelliteClient(this, cfg);
|
||||
if (!m_satellite_client->initialize())
|
||||
{
|
||||
std::cerr << "*** ERROR: Failed to initialize satellite connection"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
// Satellites don't participate in the trunk mesh
|
||||
return true;
|
||||
}
|
||||
|
||||
initTrunkLinks();
|
||||
initSatelliteServer();
|
||||
|
||||
return true;
|
||||
} /* Reflector::initialize */
|
||||
@@ -1265,9 +1292,20 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port,
|
||||
ReflectorClient::mkAndFilter(
|
||||
ReflectorClient::ExceptFilter(client),
|
||||
ReflectorClient::TgFilter(tg)));
|
||||
for (auto* link : m_trunk_links)
|
||||
if (m_is_satellite && m_satellite_client != nullptr)
|
||||
{
|
||||
link->onLocalAudio(tg, msg.audioData());
|
||||
m_satellite_client->onLocalAudio(tg, msg.audioData());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->onLocalAudio(tg, msg.audioData());
|
||||
}
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
kv.second->onParentAudio(tg, msg.audioData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1316,9 +1354,20 @@ void Reflector::udpDatagramReceived(const IpAddress& addr, uint16_t port,
|
||||
if ((tg > 0) && (client == talker))
|
||||
{
|
||||
TGHandler::instance()->setTalkerForTG(tg, 0);
|
||||
for (auto* link : m_trunk_links)
|
||||
if (m_is_satellite && m_satellite_client != nullptr)
|
||||
{
|
||||
link->onLocalFlush(tg);
|
||||
m_satellite_client->onLocalFlush(tg);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->onLocalFlush(tg);
|
||||
}
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
kv.second->onParentFlush(tg);
|
||||
}
|
||||
}
|
||||
}
|
||||
// To be 100% correct the reflector should wait for all connected
|
||||
@@ -1416,19 +1465,43 @@ void Reflector::onTalkerUpdated(uint32_t tg, ReflectorClient* old_talker,
|
||||
}
|
||||
}
|
||||
|
||||
// Notify trunk peers about local talker changes.
|
||||
// TrunkLink::handleMsgTrunkTalkerStart may set m_yielded_tgs for a TG when
|
||||
// deferring to the peer; in that case onTalkerUpdated fires with
|
||||
// new_talker==nullptr, which we must not re-broadcast as a stop to peers.
|
||||
for (auto* link : m_trunk_links)
|
||||
// In satellite mode, forward to parent instead of trunk peers
|
||||
if (m_is_satellite && m_satellite_client != nullptr)
|
||||
{
|
||||
if (new_talker != nullptr)
|
||||
{
|
||||
link->onLocalTalkerStart(tg, new_talker->callsign());
|
||||
m_satellite_client->onLocalTalkerStart(tg, new_talker->callsign());
|
||||
}
|
||||
else
|
||||
{
|
||||
link->onLocalTalkerStop(tg);
|
||||
m_satellite_client->onLocalTalkerStop(tg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Notify trunk peers about local talker changes.
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
if (new_talker != nullptr)
|
||||
{
|
||||
link->onLocalTalkerStart(tg, new_talker->callsign());
|
||||
}
|
||||
else
|
||||
{
|
||||
link->onLocalTalkerStop(tg);
|
||||
}
|
||||
}
|
||||
// Notify connected satellites
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
if (new_talker != nullptr)
|
||||
{
|
||||
kv.second->onParentTalkerStart(tg, new_talker->callsign());
|
||||
}
|
||||
else
|
||||
{
|
||||
kv.second->onParentTalkerStop(tg);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* Reflector::onTalkerUpdated */
|
||||
@@ -1505,6 +1578,35 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
||||
cfg_json["http_port"] = http_port;
|
||||
}
|
||||
|
||||
// Satellite config
|
||||
if (m_is_satellite)
|
||||
{
|
||||
cfg_json["mode"] = "satellite";
|
||||
std::string sat_of, sat_port_str, sat_id;
|
||||
m_cfg->getValue("GLOBAL", "SATELLITE_OF", sat_of);
|
||||
m_cfg->getValue("GLOBAL", "SATELLITE_PORT", sat_port_str);
|
||||
m_cfg->getValue("GLOBAL", "SATELLITE_ID", sat_id);
|
||||
Json::Value sat_cfg(Json::objectValue);
|
||||
sat_cfg["parent_host"] = sat_of;
|
||||
if (!sat_port_str.empty()) sat_cfg["parent_port"] = sat_port_str;
|
||||
if (!sat_id.empty()) sat_cfg["id"] = sat_id;
|
||||
cfg_json["satellite"] = sat_cfg;
|
||||
}
|
||||
else
|
||||
{
|
||||
cfg_json["mode"] = "reflector";
|
||||
// Satellite server config (if accepting satellites)
|
||||
std::string sat_listen_port;
|
||||
if (m_cfg->getValue("SATELLITE", "LISTEN_PORT", sat_listen_port))
|
||||
{
|
||||
Json::Value sat_srv(Json::objectValue);
|
||||
sat_srv["listen_port"] = sat_listen_port;
|
||||
sat_srv["connected_count"] =
|
||||
static_cast<Json::UInt>(m_satellite_con_map.size());
|
||||
cfg_json["satellite_server"] = sat_srv;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
@@ -1544,6 +1646,20 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
||||
}
|
||||
m_status["cluster_tgs"] = cluster_arr;
|
||||
|
||||
if (!m_satellite_con_map.empty())
|
||||
{
|
||||
Json::Value sats(Json::objectValue);
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
auto* sat = kv.second;
|
||||
if (!sat->satelliteId().empty())
|
||||
{
|
||||
sats[sat->satelliteId()] = sat->statusJson();
|
||||
}
|
||||
}
|
||||
m_status["satellites"] = sats;
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
Json::StreamWriterBuilder builder;
|
||||
builder["commentStyle"] = "None";
|
||||
@@ -1916,6 +2032,116 @@ void Reflector::initTrunkLinks(void)
|
||||
} /* Reflector::initTrunkLinks */
|
||||
|
||||
|
||||
void Reflector::initSatelliteServer(void)
|
||||
{
|
||||
std::string sat_port;
|
||||
std::string sat_secret;
|
||||
if (!m_cfg->getValue("SATELLITE", "LISTEN_PORT", sat_port) ||
|
||||
!m_cfg->getValue("SATELLITE", "SECRET", sat_secret) ||
|
||||
sat_secret.empty())
|
||||
{
|
||||
return; // No [SATELLITE] section — not accepting satellites
|
||||
}
|
||||
|
||||
m_satellite_secret = sat_secret;
|
||||
m_sat_srv = new TcpServer<FramedTcpConnection>(sat_port);
|
||||
m_sat_srv->setConnectionThrottling(10, 0.1, 1000);
|
||||
m_sat_srv->clientConnected.connect(
|
||||
sigc::mem_fun(*this, &Reflector::satelliteConnected));
|
||||
m_sat_srv->clientDisconnected.connect(
|
||||
sigc::mem_fun(*this, &Reflector::satelliteDisconnected));
|
||||
|
||||
std::cout << "Satellite server listening on port " << sat_port << std::endl;
|
||||
} /* Reflector::initSatelliteServer */
|
||||
|
||||
|
||||
void Reflector::satelliteConnected(Async::FramedTcpConnection* con)
|
||||
{
|
||||
std::cout << "SAT: Inbound connection from "
|
||||
<< con->remoteHost() << ":" << con->remotePort() << std::endl;
|
||||
auto* link = new SatelliteLink(this, con, m_satellite_secret);
|
||||
m_satellite_con_map[con] = link;
|
||||
} /* Reflector::satelliteConnected */
|
||||
|
||||
|
||||
void Reflector::satelliteDisconnected(Async::FramedTcpConnection* con,
|
||||
Async::FramedTcpConnection::DisconnectReason reason)
|
||||
{
|
||||
auto it = m_satellite_con_map.find(con);
|
||||
if (it != m_satellite_con_map.end())
|
||||
{
|
||||
std::cout << "SAT: Satellite '" << it->second->satelliteId()
|
||||
<< "' disconnected" << std::endl;
|
||||
delete it->second;
|
||||
m_satellite_con_map.erase(it);
|
||||
}
|
||||
} /* Reflector::satelliteDisconnected */
|
||||
|
||||
|
||||
void Reflector::forwardSatelliteAudioToTrunks(uint32_t tg,
|
||||
const std::string& callsign)
|
||||
{
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->onLocalTalkerStart(tg, callsign);
|
||||
}
|
||||
} /* Reflector::forwardSatelliteAudioToTrunks */
|
||||
|
||||
|
||||
void Reflector::forwardSatelliteStopToTrunks(uint32_t tg)
|
||||
{
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->onLocalTalkerStop(tg);
|
||||
}
|
||||
} /* Reflector::forwardSatelliteStopToTrunks */
|
||||
|
||||
|
||||
void Reflector::forwardSatelliteRawAudioToTrunks(uint32_t tg,
|
||||
const std::vector<uint8_t>& audio)
|
||||
{
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->onLocalAudio(tg, audio);
|
||||
}
|
||||
} /* Reflector::forwardSatelliteRawAudioToTrunks */
|
||||
|
||||
|
||||
void Reflector::forwardSatelliteFlushToTrunks(uint32_t tg)
|
||||
{
|
||||
for (auto* link : m_trunk_links)
|
||||
{
|
||||
link->onLocalFlush(tg);
|
||||
}
|
||||
} /* Reflector::forwardSatelliteFlushToTrunks */
|
||||
|
||||
|
||||
void Reflector::forwardAudioToSatellitesExcept(SatelliteLink* except,
|
||||
uint32_t tg, const std::vector<uint8_t>& audio)
|
||||
{
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
if (kv.second != except)
|
||||
{
|
||||
kv.second->onParentAudio(tg, audio);
|
||||
}
|
||||
}
|
||||
} /* Reflector::forwardAudioToSatellitesExcept */
|
||||
|
||||
|
||||
void Reflector::forwardFlushToSatellitesExcept(SatelliteLink* except,
|
||||
uint32_t tg)
|
||||
{
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
if (kv.second != except)
|
||||
{
|
||||
kv.second->onParentFlush(tg);
|
||||
}
|
||||
}
|
||||
} /* Reflector::forwardFlushToSatellitesExcept */
|
||||
|
||||
|
||||
void Reflector::onTrunkTalkerUpdated(uint32_t tg,
|
||||
std::string old_cs, std::string new_cs)
|
||||
{
|
||||
@@ -1940,6 +2166,19 @@ void Reflector::onTrunkTalkerUpdated(uint32_t tg,
|
||||
ge_v2_client_filter,
|
||||
ReflectorClient::TgFilter(tg)));
|
||||
}
|
||||
|
||||
// Forward trunk talker events to connected satellites
|
||||
for (auto& kv : m_satellite_con_map)
|
||||
{
|
||||
if (!new_cs.empty())
|
||||
{
|
||||
kv.second->onParentTalkerStart(tg, new_cs);
|
||||
}
|
||||
else if (!old_cs.empty())
|
||||
{
|
||||
kv.second->onParentTalkerStop(tg);
|
||||
}
|
||||
}
|
||||
} /* Reflector::onTrunkTalkerUpdated */
|
||||
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include "ProtoVer.h"
|
||||
#include "ReflectorClient.h"
|
||||
#include "TrunkLink.h"
|
||||
#include "SatelliteLink.h"
|
||||
#include "SatelliteClient.h"
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
@@ -238,6 +240,18 @@ class Reflector : public sigc::trackable
|
||||
Json::Value& clientStatus(const std::string& callsign);
|
||||
|
||||
bool isClusterTG(uint32_t tg) const { return m_cluster_tgs.count(tg) > 0; }
|
||||
bool isSatelliteMode(void) const { return m_is_satellite; }
|
||||
|
||||
// Callbacks for SatelliteLink to forward satellite events to trunk peers
|
||||
void forwardSatelliteAudioToTrunks(uint32_t tg,
|
||||
const std::string& callsign);
|
||||
void forwardSatelliteStopToTrunks(uint32_t tg);
|
||||
void forwardSatelliteRawAudioToTrunks(uint32_t tg,
|
||||
const std::vector<uint8_t>& audio);
|
||||
void forwardSatelliteFlushToTrunks(uint32_t tg);
|
||||
void forwardAudioToSatellitesExcept(SatelliteLink* except, uint32_t tg,
|
||||
const std::vector<uint8_t>& audio);
|
||||
void forwardFlushToSatellitesExcept(SatelliteLink* except, uint32_t tg);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -286,6 +300,13 @@ class Reflector : public sigc::trackable
|
||||
std::vector<TrunkLink*> m_trunk_links;
|
||||
std::set<uint32_t> m_cluster_tgs;
|
||||
|
||||
// Satellite support
|
||||
bool m_is_satellite = false;
|
||||
SatelliteClient* m_satellite_client = nullptr;
|
||||
FramedTcpServer* m_sat_srv = nullptr;
|
||||
std::string m_satellite_secret;
|
||||
std::map<Async::FramedTcpConnection*, SatelliteLink*> m_satellite_con_map;
|
||||
|
||||
Reflector(const Reflector&);
|
||||
Reflector& operator=(const Reflector&);
|
||||
void clientConnected(Async::FramedTcpConnection *con);
|
||||
@@ -309,6 +330,10 @@ class Reflector : public sigc::trackable
|
||||
void onTrunkTalkerUpdated(uint32_t tg, std::string old_cs,
|
||||
std::string new_cs);
|
||||
void initTrunkLinks(void);
|
||||
void initSatelliteServer(void);
|
||||
void satelliteConnected(Async::FramedTcpConnection* con);
|
||||
void satelliteDisconnected(Async::FramedTcpConnection* con,
|
||||
Async::FramedTcpConnection::DisconnectReason reason);
|
||||
bool loadCertificateFiles(void);
|
||||
bool loadServerCertificateFiles(void);
|
||||
bool generateKeyFile(Async::SslKeypair& pkey, const std::string& keyfile);
|
||||
|
||||
@@ -1415,7 +1415,10 @@ class MsgTrunkHello : public ReflectorMsgBase<115>
|
||||
public:
|
||||
static const size_t NONCE_LEN = 20;
|
||||
|
||||
MsgTrunkHello(void) : m_priority(0) {}
|
||||
static const uint8_t ROLE_PEER = 0;
|
||||
static const uint8_t ROLE_SATELLITE = 1;
|
||||
|
||||
MsgTrunkHello(void) : m_priority(0), m_role(ROLE_PEER) {}
|
||||
|
||||
/**
|
||||
* @brief Constructor that generates a nonce and computes HMAC
|
||||
@@ -1423,13 +1426,15 @@ class MsgTrunkHello : public ReflectorMsgBase<115>
|
||||
* @param local_prefix Comma-separated TG prefix list
|
||||
* @param priority Tie-break nonce
|
||||
* @param secret Shared secret for HMAC authentication
|
||||
* @param role ROLE_PEER (default) or ROLE_SATELLITE
|
||||
*/
|
||||
MsgTrunkHello(const std::string& id,
|
||||
const std::string& local_prefix,
|
||||
uint32_t priority,
|
||||
const std::string& secret)
|
||||
const std::string& secret,
|
||||
uint8_t role = ROLE_PEER)
|
||||
: m_id(id), m_local_prefix(local_prefix), m_priority(priority),
|
||||
m_nonce(NONCE_LEN)
|
||||
m_role(role), m_nonce(NONCE_LEN)
|
||||
{
|
||||
int rc = RAND_bytes(&m_nonce.front(), NONCE_LEN);
|
||||
if (rc != 1)
|
||||
@@ -1449,6 +1454,7 @@ class MsgTrunkHello : public ReflectorMsgBase<115>
|
||||
const std::string& id(void) const { return m_id; }
|
||||
const std::string& localPrefix(void) const { return m_local_prefix; }
|
||||
uint32_t priority(void) const { return m_priority; }
|
||||
uint8_t role(void) const { return m_role; }
|
||||
|
||||
/**
|
||||
* @brief Verify that the peer knows the shared secret
|
||||
@@ -1470,12 +1476,14 @@ class MsgTrunkHello : public ReflectorMsgBase<115>
|
||||
Async::Digest::sigEqual(m_digest, expected);
|
||||
}
|
||||
|
||||
ASYNC_MSG_MEMBERS(m_id, m_local_prefix, m_priority, m_nonce, m_digest)
|
||||
ASYNC_MSG_MEMBERS(m_id, m_local_prefix, m_priority, m_nonce, m_digest,
|
||||
m_role)
|
||||
|
||||
private:
|
||||
std::string m_id;
|
||||
std::string m_local_prefix;
|
||||
uint32_t m_priority;
|
||||
uint8_t m_role;
|
||||
std::vector<uint8_t> m_nonce;
|
||||
std::vector<uint8_t> m_digest;
|
||||
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
|
||||
#include <AsyncTcpConnection.h>
|
||||
|
||||
#include "SatelliteClient.h"
|
||||
#include "ReflectorMsg.h"
|
||||
#include "Reflector.h"
|
||||
#include "TGHandler.h"
|
||||
#include "ReflectorClient.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Async;
|
||||
using namespace sigc;
|
||||
|
||||
|
||||
SatelliteClient::SatelliteClient(Reflector* reflector, Async::Config& cfg)
|
||||
: m_reflector(reflector), m_cfg(cfg),
|
||||
m_parent_port(5303), m_priority(0), m_hello_received(false),
|
||||
m_heartbeat_timer(1000, Timer::TYPE_PERIODIC, false),
|
||||
m_hb_tx_cnt(0), m_hb_rx_cnt(0)
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 rng(rd());
|
||||
std::uniform_int_distribution<uint32_t> dist;
|
||||
m_priority = dist(rng);
|
||||
|
||||
m_con.connected.connect(mem_fun(*this, &SatelliteClient::onConnected));
|
||||
m_con.disconnected.connect(mem_fun(*this, &SatelliteClient::onDisconnected));
|
||||
m_con.frameReceived.connect(mem_fun(*this, &SatelliteClient::onFrameReceived));
|
||||
m_con.setMaxFrameSize(ReflectorMsg::MAX_POSTAUTH_FRAME_SIZE);
|
||||
|
||||
m_heartbeat_timer.expired.connect(
|
||||
mem_fun(*this, &SatelliteClient::heartbeatTick));
|
||||
} /* SatelliteClient::SatelliteClient */
|
||||
|
||||
|
||||
SatelliteClient::~SatelliteClient(void)
|
||||
{
|
||||
TGHandler::instance()->clearAllTrunkTalkers();
|
||||
} /* SatelliteClient::~SatelliteClient */
|
||||
|
||||
|
||||
bool SatelliteClient::initialize(void)
|
||||
{
|
||||
if (!m_cfg.getValue("GLOBAL", "SATELLITE_OF", m_parent_host) ||
|
||||
m_parent_host.empty())
|
||||
{
|
||||
cerr << "*** ERROR: Missing SATELLITE_OF in [GLOBAL]" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_cfg.getValue("GLOBAL", "SATELLITE_PORT", m_parent_port);
|
||||
|
||||
if (!m_cfg.getValue("GLOBAL", "SATELLITE_SECRET", m_secret) ||
|
||||
m_secret.empty())
|
||||
{
|
||||
cerr << "*** ERROR: Missing SATELLITE_SECRET in [GLOBAL]" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use a satellite ID — hostname or configured name
|
||||
m_satellite_id = "satellite";
|
||||
m_cfg.getValue("GLOBAL", "SATELLITE_ID", m_satellite_id);
|
||||
|
||||
cout << "SATELLITE: Connecting to parent " << m_parent_host
|
||||
<< ":" << m_parent_port << " as '" << m_satellite_id << "'" << endl;
|
||||
|
||||
m_con.addStaticSRVRecord(0, 0, 0, m_parent_port, m_parent_host);
|
||||
m_con.connect();
|
||||
|
||||
return true;
|
||||
} /* SatelliteClient::initialize */
|
||||
|
||||
|
||||
void SatelliteClient::onLocalTalkerStart(uint32_t tg,
|
||||
const std::string& callsign)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
sendMsg(MsgTrunkTalkerStart(tg, callsign));
|
||||
} /* SatelliteClient::onLocalTalkerStart */
|
||||
|
||||
|
||||
void SatelliteClient::onLocalTalkerStop(uint32_t tg)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
sendMsg(MsgTrunkTalkerStop(tg));
|
||||
} /* SatelliteClient::onLocalTalkerStop */
|
||||
|
||||
|
||||
void SatelliteClient::onLocalAudio(uint32_t tg,
|
||||
const std::vector<uint8_t>& audio)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
sendMsg(MsgTrunkAudio(tg, audio));
|
||||
} /* SatelliteClient::onLocalAudio */
|
||||
|
||||
|
||||
void SatelliteClient::onLocalFlush(uint32_t tg)
|
||||
{
|
||||
if (!m_con.isConnected() || !m_hello_received) return;
|
||||
sendMsg(MsgTrunkFlush(tg));
|
||||
} /* SatelliteClient::onLocalFlush */
|
||||
|
||||
|
||||
void SatelliteClient::onConnected(void)
|
||||
{
|
||||
cout << "SATELLITE: Connected to parent " << m_con.remoteHost()
|
||||
<< ":" << m_con.remotePort() << endl;
|
||||
|
||||
m_hello_received = false;
|
||||
m_hb_tx_cnt = HEARTBEAT_TX_CNT_RESET;
|
||||
m_hb_rx_cnt = HEARTBEAT_RX_CNT_RESET;
|
||||
|
||||
sendMsg(MsgTrunkHello(m_satellite_id, "", m_priority, m_secret,
|
||||
MsgTrunkHello::ROLE_SATELLITE));
|
||||
|
||||
m_heartbeat_timer.setEnable(true);
|
||||
} /* SatelliteClient::onConnected */
|
||||
|
||||
|
||||
void SatelliteClient::onDisconnected(TcpConnection* con,
|
||||
TcpConnection::DisconnectReason reason)
|
||||
{
|
||||
cout << "SATELLITE: Disconnected from parent: "
|
||||
<< TcpConnection::disconnectReasonStr(reason) << endl;
|
||||
|
||||
m_heartbeat_timer.setEnable(false);
|
||||
m_hello_received = false;
|
||||
TGHandler::instance()->clearAllTrunkTalkers();
|
||||
} /* SatelliteClient::onDisconnected */
|
||||
|
||||
|
||||
void SatelliteClient::onFrameReceived(FramedTcpConnection* con,
|
||||
std::vector<uint8_t>& data)
|
||||
{
|
||||
auto buf = reinterpret_cast<const char*>(data.data());
|
||||
stringstream ss;
|
||||
ss.write(buf, data.size());
|
||||
|
||||
ReflectorMsg header;
|
||||
if (!header.unpack(ss))
|
||||
{
|
||||
cerr << "*** ERROR[SATELLITE]: Failed to unpack message header" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_hello_received &&
|
||||
header.type() != MsgTrunkHello::TYPE &&
|
||||
header.type() != MsgTrunkHeartbeat::TYPE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_hb_rx_cnt = HEARTBEAT_RX_CNT_RESET;
|
||||
|
||||
switch (header.type())
|
||||
{
|
||||
case MsgTrunkHeartbeat::TYPE:
|
||||
handleMsgTrunkHeartbeat();
|
||||
break;
|
||||
case MsgTrunkHello::TYPE:
|
||||
handleMsgTrunkHello(ss);
|
||||
break;
|
||||
case MsgTrunkTalkerStart::TYPE:
|
||||
handleMsgTrunkTalkerStart(ss);
|
||||
break;
|
||||
case MsgTrunkTalkerStop::TYPE:
|
||||
handleMsgTrunkTalkerStop(ss);
|
||||
break;
|
||||
case MsgTrunkAudio::TYPE:
|
||||
handleMsgTrunkAudio(ss);
|
||||
break;
|
||||
case MsgTrunkFlush::TYPE:
|
||||
handleMsgTrunkFlush(ss);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} /* SatelliteClient::onFrameReceived */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkHeartbeat(void)
|
||||
{
|
||||
} /* SatelliteClient::handleMsgTrunkHeartbeat */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkHello(std::istream& is)
|
||||
{
|
||||
MsgTrunkHello msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cerr << "*** ERROR[SATELLITE]: Failed to unpack MsgTrunkHello" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!msg.verify(m_secret))
|
||||
{
|
||||
cerr << "*** ERROR[SATELLITE]: Parent authentication failed" << endl;
|
||||
m_con.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
m_hello_received = true;
|
||||
cout << "SATELLITE: Parent authenticated (id='" << msg.id() << "')" << endl;
|
||||
} /* SatelliteClient::handleMsgTrunkHello */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkTalkerStart(std::istream& is)
|
||||
{
|
||||
MsgTrunkTalkerStart msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
// Register as trunk talker — fires trunkTalkerUpdated which
|
||||
// broadcasts MsgTalkerStart to local clients
|
||||
TGHandler::instance()->setTrunkTalkerForTG(msg.tg(), msg.callsign());
|
||||
} /* SatelliteClient::handleMsgTrunkTalkerStart */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkTalkerStop(std::istream& is)
|
||||
{
|
||||
MsgTrunkTalkerStop msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
TGHandler::instance()->clearTrunkTalkerForTG(msg.tg());
|
||||
} /* SatelliteClient::handleMsgTrunkTalkerStop */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkAudio(std::istream& is)
|
||||
{
|
||||
MsgTrunkAudio msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
if (msg.audio().empty()) return;
|
||||
|
||||
MsgUdpAudio udp_msg(msg.audio());
|
||||
m_reflector->broadcastUdpMsg(udp_msg,
|
||||
ReflectorClient::TgFilter(msg.tg()));
|
||||
} /* SatelliteClient::handleMsgTrunkAudio */
|
||||
|
||||
|
||||
void SatelliteClient::handleMsgTrunkFlush(std::istream& is)
|
||||
{
|
||||
MsgTrunkFlush msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||
ReflectorClient::TgFilter(msg.tg()));
|
||||
} /* SatelliteClient::handleMsgTrunkFlush */
|
||||
|
||||
|
||||
void SatelliteClient::sendMsg(const ReflectorMsg& msg)
|
||||
{
|
||||
ostringstream ss;
|
||||
ReflectorMsg header(msg.type());
|
||||
if (!header.pack(ss) || !msg.pack(ss))
|
||||
{
|
||||
cerr << "*** ERROR[SATELLITE]: Failed to pack message type="
|
||||
<< msg.type() << endl;
|
||||
return;
|
||||
}
|
||||
m_hb_tx_cnt = HEARTBEAT_TX_CNT_RESET;
|
||||
m_con.write(ss.str().data(), ss.str().size());
|
||||
} /* SatelliteClient::sendMsg */
|
||||
|
||||
|
||||
void SatelliteClient::heartbeatTick(Async::Timer* t)
|
||||
{
|
||||
if (--m_hb_tx_cnt == 0)
|
||||
{
|
||||
m_hb_tx_cnt = HEARTBEAT_TX_CNT_RESET;
|
||||
sendMsg(MsgTrunkHeartbeat());
|
||||
}
|
||||
|
||||
if (--m_hb_rx_cnt == 0)
|
||||
{
|
||||
cerr << "*** ERROR[SATELLITE]: Heartbeat timeout — disconnecting" << endl;
|
||||
m_con.disconnect();
|
||||
}
|
||||
} /* SatelliteClient::heartbeatTick */
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef SATELLITE_CLIENT_INCLUDED
|
||||
#define SATELLITE_CLIENT_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <AsyncConfig.h>
|
||||
#include <AsyncTcpPrioClient.h>
|
||||
#include <AsyncFramedTcpConnection.h>
|
||||
#include <AsyncTimer.h>
|
||||
|
||||
class Reflector;
|
||||
class ReflectorMsg;
|
||||
|
||||
/**
|
||||
@brief Satellite-side outbound connection to a parent reflector
|
||||
|
||||
When SATELLITE_OF is configured, the reflector runs in satellite mode:
|
||||
it connects to a parent reflector and relays all local client events.
|
||||
Events received from the parent are broadcast to local clients.
|
||||
No prefix logic, no trunk mesh participation.
|
||||
*/
|
||||
class SatelliteClient : public sigc::trackable
|
||||
{
|
||||
public:
|
||||
SatelliteClient(Reflector* reflector, Async::Config& cfg);
|
||||
~SatelliteClient(void);
|
||||
|
||||
bool initialize(void);
|
||||
|
||||
// Called by Reflector when a local client starts/stops talking
|
||||
void onLocalTalkerStart(uint32_t tg, const std::string& callsign);
|
||||
void onLocalTalkerStop(uint32_t tg);
|
||||
void onLocalAudio(uint32_t tg, const std::vector<uint8_t>& audio);
|
||||
void onLocalFlush(uint32_t tg);
|
||||
|
||||
private:
|
||||
static const unsigned HEARTBEAT_TX_CNT_RESET = 10;
|
||||
static const unsigned HEARTBEAT_RX_CNT_RESET = 15;
|
||||
|
||||
using FramedTcpClient =
|
||||
Async::TcpPrioClient<Async::FramedTcpConnection>;
|
||||
|
||||
Reflector* m_reflector;
|
||||
Async::Config& m_cfg;
|
||||
std::string m_parent_host;
|
||||
uint16_t m_parent_port;
|
||||
std::string m_secret;
|
||||
std::string m_satellite_id;
|
||||
uint32_t m_priority;
|
||||
bool m_hello_received;
|
||||
FramedTcpClient m_con;
|
||||
Async::Timer m_heartbeat_timer;
|
||||
unsigned m_hb_tx_cnt;
|
||||
unsigned m_hb_rx_cnt;
|
||||
|
||||
void onConnected(void);
|
||||
void onDisconnected(Async::TcpConnection* con,
|
||||
Async::TcpConnection::DisconnectReason reason);
|
||||
void onFrameReceived(Async::FramedTcpConnection* con,
|
||||
std::vector<uint8_t>& data);
|
||||
void handleMsgTrunkHello(std::istream& is);
|
||||
void handleMsgTrunkTalkerStart(std::istream& is);
|
||||
void handleMsgTrunkTalkerStop(std::istream& is);
|
||||
void handleMsgTrunkAudio(std::istream& is);
|
||||
void handleMsgTrunkFlush(std::istream& is);
|
||||
void handleMsgTrunkHeartbeat(void);
|
||||
void sendMsg(const ReflectorMsg& msg);
|
||||
void heartbeatTick(Async::Timer* t);
|
||||
};
|
||||
|
||||
#endif /* SATELLITE_CLIENT_INCLUDED */
|
||||
@@ -0,0 +1,285 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "SatelliteLink.h"
|
||||
#include "ReflectorMsg.h"
|
||||
#include "Reflector.h"
|
||||
#include "TGHandler.h"
|
||||
#include "ReflectorClient.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Async;
|
||||
|
||||
|
||||
SatelliteLink::SatelliteLink(Reflector* reflector,
|
||||
Async::FramedTcpConnection* con,
|
||||
const std::string& secret)
|
||||
: m_reflector(reflector), m_con(con), m_secret(secret),
|
||||
m_hello_received(false),
|
||||
m_heartbeat_timer(1000, Timer::TYPE_PERIODIC),
|
||||
m_hb_tx_cnt(HEARTBEAT_TX_CNT_RESET),
|
||||
m_hb_rx_cnt(HEARTBEAT_RX_CNT_RESET)
|
||||
{
|
||||
m_con->setMaxFrameSize(ReflectorMsg::MAX_POSTAUTH_FRAME_SIZE);
|
||||
m_con->frameReceived.connect(
|
||||
sigc::mem_fun(*this, &SatelliteLink::onFrameReceived));
|
||||
|
||||
m_heartbeat_timer.expired.connect(
|
||||
sigc::mem_fun(*this, &SatelliteLink::heartbeatTick));
|
||||
} /* SatelliteLink::SatelliteLink */
|
||||
|
||||
|
||||
SatelliteLink::~SatelliteLink(void)
|
||||
{
|
||||
m_heartbeat_timer.setEnable(false);
|
||||
for (uint32_t tg : m_sat_active_tgs)
|
||||
{
|
||||
TGHandler::instance()->clearTrunkTalkerForTG(tg);
|
||||
}
|
||||
m_sat_active_tgs.clear();
|
||||
} /* SatelliteLink::~SatelliteLink */
|
||||
|
||||
|
||||
Json::Value SatelliteLink::statusJson(void) const
|
||||
{
|
||||
Json::Value obj(Json::objectValue);
|
||||
obj["id"] = m_satellite_id;
|
||||
obj["authenticated"] = m_hello_received;
|
||||
|
||||
Json::Value active_tgs(Json::arrayValue);
|
||||
for (uint32_t tg : m_sat_active_tgs)
|
||||
{
|
||||
active_tgs.append(tg);
|
||||
}
|
||||
obj["active_tgs"] = active_tgs;
|
||||
return obj;
|
||||
} /* SatelliteLink::statusJson */
|
||||
|
||||
|
||||
void SatelliteLink::onParentTalkerStart(uint32_t tg,
|
||||
const std::string& callsign)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
sendMsg(MsgTrunkTalkerStart(tg, callsign));
|
||||
} /* SatelliteLink::onParentTalkerStart */
|
||||
|
||||
|
||||
void SatelliteLink::onParentTalkerStop(uint32_t tg)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
sendMsg(MsgTrunkTalkerStop(tg));
|
||||
} /* SatelliteLink::onParentTalkerStop */
|
||||
|
||||
|
||||
void SatelliteLink::onParentAudio(uint32_t tg,
|
||||
const std::vector<uint8_t>& audio)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
sendMsg(MsgTrunkAudio(tg, audio));
|
||||
} /* SatelliteLink::onParentAudio */
|
||||
|
||||
|
||||
void SatelliteLink::onParentFlush(uint32_t tg)
|
||||
{
|
||||
if (!m_hello_received) return;
|
||||
sendMsg(MsgTrunkFlush(tg));
|
||||
} /* SatelliteLink::onParentFlush */
|
||||
|
||||
|
||||
void SatelliteLink::onFrameReceived(FramedTcpConnection* con,
|
||||
std::vector<uint8_t>& data)
|
||||
{
|
||||
auto buf = reinterpret_cast<const char*>(data.data());
|
||||
stringstream ss;
|
||||
ss.write(buf, data.size());
|
||||
|
||||
ReflectorMsg header;
|
||||
if (!header.unpack(ss))
|
||||
{
|
||||
cerr << "*** ERROR[SAT]: Failed to unpack satellite message header"
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_hello_received &&
|
||||
header.type() != MsgTrunkHello::TYPE &&
|
||||
header.type() != MsgTrunkHeartbeat::TYPE)
|
||||
{
|
||||
cerr << "*** WARNING[SAT]: Ignoring message type=" << header.type()
|
||||
<< " before hello" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
m_hb_rx_cnt = HEARTBEAT_RX_CNT_RESET;
|
||||
|
||||
switch (header.type())
|
||||
{
|
||||
case MsgTrunkHeartbeat::TYPE:
|
||||
handleMsgTrunkHeartbeat();
|
||||
break;
|
||||
case MsgTrunkHello::TYPE:
|
||||
handleMsgTrunkHello(ss);
|
||||
break;
|
||||
case MsgTrunkTalkerStart::TYPE:
|
||||
handleMsgTrunkTalkerStart(ss);
|
||||
break;
|
||||
case MsgTrunkTalkerStop::TYPE:
|
||||
handleMsgTrunkTalkerStop(ss);
|
||||
break;
|
||||
case MsgTrunkAudio::TYPE:
|
||||
handleMsgTrunkAudio(ss);
|
||||
break;
|
||||
case MsgTrunkFlush::TYPE:
|
||||
handleMsgTrunkFlush(ss);
|
||||
break;
|
||||
default:
|
||||
cerr << "*** WARNING[SAT]: Unknown message type=" << header.type()
|
||||
<< endl;
|
||||
break;
|
||||
}
|
||||
} /* SatelliteLink::onFrameReceived */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkHeartbeat(void)
|
||||
{
|
||||
} /* SatelliteLink::handleMsgTrunkHeartbeat */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkHello(std::istream& is)
|
||||
{
|
||||
MsgTrunkHello msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
cerr << "*** ERROR[SAT]: Failed to unpack MsgTrunkHello" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.id().empty())
|
||||
{
|
||||
cerr << "*** ERROR[SAT]: Satellite sent empty ID" << endl;
|
||||
m_con->disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.role() != MsgTrunkHello::ROLE_SATELLITE)
|
||||
{
|
||||
cerr << "*** ERROR[SAT]: Expected ROLE_SATELLITE from '" << msg.id()
|
||||
<< "' but got role=" << (int)msg.role() << endl;
|
||||
m_con->disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!msg.verify(m_secret))
|
||||
{
|
||||
cerr << "*** ERROR[SAT]: Authentication failed for satellite '"
|
||||
<< msg.id() << "'" << endl;
|
||||
m_con->disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
m_satellite_id = msg.id();
|
||||
m_hello_received = true;
|
||||
|
||||
cout << "SAT: Satellite '" << m_satellite_id
|
||||
<< "' authenticated" << endl;
|
||||
} /* SatelliteLink::handleMsgTrunkHello */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkTalkerStart(std::istream& is)
|
||||
{
|
||||
MsgTrunkTalkerStart msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
|
||||
// Register as trunk talker — fires trunkTalkerUpdated which notifies
|
||||
// local clients. Reflector::onTrunkTalkerUpdated also forwards to
|
||||
// other satellites and trunk peers.
|
||||
m_sat_active_tgs.insert(tg);
|
||||
TGHandler::instance()->setTrunkTalkerForTG(tg, msg.callsign());
|
||||
|
||||
// Forward to trunk peers
|
||||
m_reflector->forwardSatelliteAudioToTrunks(tg, msg.callsign());
|
||||
} /* SatelliteLink::handleMsgTrunkTalkerStart */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkTalkerStop(std::istream& is)
|
||||
{
|
||||
MsgTrunkTalkerStop msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
m_sat_active_tgs.erase(tg);
|
||||
TGHandler::instance()->clearTrunkTalkerForTG(tg);
|
||||
|
||||
// Forward stop to trunk peers
|
||||
m_reflector->forwardSatelliteStopToTrunks(tg);
|
||||
} /* SatelliteLink::handleMsgTrunkTalkerStop */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkAudio(std::istream& is)
|
||||
{
|
||||
MsgTrunkAudio msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
if (msg.audio().empty()) return;
|
||||
if (m_sat_active_tgs.find(tg) == m_sat_active_tgs.end()) return;
|
||||
|
||||
// Broadcast to local clients on the parent
|
||||
MsgUdpAudio udp_msg(msg.audio());
|
||||
m_reflector->broadcastUdpMsg(udp_msg, ReflectorClient::TgFilter(tg));
|
||||
|
||||
// Forward to trunk peers
|
||||
m_reflector->forwardSatelliteRawAudioToTrunks(tg, msg.audio());
|
||||
|
||||
// Forward to other satellites (not this one)
|
||||
m_reflector->forwardAudioToSatellitesExcept(this, tg, msg.audio());
|
||||
} /* SatelliteLink::handleMsgTrunkAudio */
|
||||
|
||||
|
||||
void SatelliteLink::handleMsgTrunkFlush(std::istream& is)
|
||||
{
|
||||
MsgTrunkFlush msg;
|
||||
if (!msg.unpack(is)) return;
|
||||
|
||||
uint32_t tg = msg.tg();
|
||||
|
||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||
ReflectorClient::TgFilter(tg));
|
||||
|
||||
m_reflector->forwardSatelliteFlushToTrunks(tg);
|
||||
m_reflector->forwardFlushToSatellitesExcept(this, tg);
|
||||
} /* SatelliteLink::handleMsgTrunkFlush */
|
||||
|
||||
|
||||
void SatelliteLink::sendMsg(const ReflectorMsg& msg)
|
||||
{
|
||||
ostringstream ss;
|
||||
ReflectorMsg header(msg.type());
|
||||
if (!header.pack(ss) || !msg.pack(ss))
|
||||
{
|
||||
cerr << "*** ERROR[SAT]: Failed to pack message type=" << msg.type()
|
||||
<< endl;
|
||||
return;
|
||||
}
|
||||
m_hb_tx_cnt = HEARTBEAT_TX_CNT_RESET;
|
||||
m_con->write(ss.str().data(), ss.str().size());
|
||||
} /* SatelliteLink::sendMsg */
|
||||
|
||||
|
||||
void SatelliteLink::heartbeatTick(Async::Timer* t)
|
||||
{
|
||||
if (--m_hb_tx_cnt == 0)
|
||||
{
|
||||
m_hb_tx_cnt = HEARTBEAT_TX_CNT_RESET;
|
||||
sendMsg(MsgTrunkHeartbeat());
|
||||
}
|
||||
|
||||
if (--m_hb_rx_cnt == 0)
|
||||
{
|
||||
cerr << "*** ERROR[SAT '" << m_satellite_id
|
||||
<< "']: Heartbeat timeout — disconnecting" << endl;
|
||||
m_con->disconnect();
|
||||
}
|
||||
} /* SatelliteLink::heartbeatTick */
|
||||
@@ -0,0 +1,65 @@
|
||||
#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>
|
||||
|
||||
class Reflector;
|
||||
class ReflectorMsg;
|
||||
|
||||
/**
|
||||
@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. It relays ALL TGs bidirectionally (no prefix filtering).
|
||||
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;
|
||||
|
||||
// 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);
|
||||
|
||||
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;
|
||||
|
||||
void onFrameReceived(Async::FramedTcpConnection* con,
|
||||
std::vector<uint8_t>& data);
|
||||
void handleMsgTrunkHello(std::istream& is);
|
||||
void handleMsgTrunkTalkerStart(std::istream& is);
|
||||
void handleMsgTrunkTalkerStop(std::istream& is);
|
||||
void handleMsgTrunkAudio(std::istream& is);
|
||||
void handleMsgTrunkFlush(std::istream& is);
|
||||
void handleMsgTrunkHeartbeat(void);
|
||||
void sendMsg(const ReflectorMsg& msg);
|
||||
void heartbeatTick(Async::Timer* t);
|
||||
};
|
||||
|
||||
#endif /* SATELLITE_LINK_INCLUDED */
|
||||
@@ -531,6 +531,9 @@ void TrunkLink::handleMsgTrunkAudio(std::istream& is)
|
||||
// Rebuild a UDP audio message and broadcast to local clients on this TG
|
||||
MsgUdpAudio udp_msg(msg.audio());
|
||||
m_reflector->broadcastUdpMsg(udp_msg, ReflectorClient::TgFilter(tg));
|
||||
|
||||
// Forward trunk audio to connected satellites
|
||||
m_reflector->forwardAudioToSatellitesExcept(nullptr, tg, msg.audio());
|
||||
} /* TrunkLink::handleMsgTrunkAudio */
|
||||
|
||||
|
||||
@@ -552,6 +555,9 @@ void TrunkLink::handleMsgTrunkFlush(std::istream& is)
|
||||
|
||||
m_reflector->broadcastUdpMsg(MsgUdpFlushSamples(),
|
||||
ReflectorClient::TgFilter(tg));
|
||||
|
||||
// Forward trunk flush to connected satellites
|
||||
m_reflector->forwardFlushToSatellitesExcept(nullptr, tg);
|
||||
} /* TrunkLink::handleMsgTrunkFlush */
|
||||
|
||||
|
||||
|
||||
@@ -100,3 +100,19 @@ CERT_CA_HOOK=@SVX_SHARE_INSTALL_DIR@/ca-hook.py
|
||||
#SECRET=change_this_shared_secret
|
||||
#REMOTE_PREFIX=2
|
||||
|
||||
# --- Satellite reflectors ---
|
||||
# A satellite is a lightweight reflector that connects to a parent
|
||||
# reflector instead of joining the trunk mesh. Clients connect to the
|
||||
# satellite normally; it relays everything to the parent.
|
||||
#
|
||||
# Parent side: accept inbound satellite connections
|
||||
#[SATELLITE]
|
||||
#LISTEN_PORT=5303
|
||||
#SECRET=change_this_satellite_secret
|
||||
#
|
||||
# Satellite side: set these in [GLOBAL] instead of LOCAL_PREFIX/TRUNK_x
|
||||
#SATELLITE_OF=reflector-01.example.com
|
||||
#SATELLITE_PORT=5303
|
||||
#SATELLITE_SECRET=change_this_satellite_secret
|
||||
#SATELLITE_ID=my-satellite
|
||||
|
||||
Reference in new issue
Block a user