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.
This commit is contained in:
1 parent
11b1a7b518
commit
81672bae23
2 files changed
+152
No files matched your search
@@ -271,6 +271,18 @@ void SatelliteClient::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:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -444,6 +456,134 @@ void SatelliteClient::sendMsg(const ReflectorMsg& msg)
|
|||||||
} /* SatelliteClient::sendMsg */
|
} /* 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<Json::UInt>(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)
|
void SatelliteClient::heartbeatTick(Async::Timer* t)
|
||||||
{
|
{
|
||||||
if (--m_hb_tx_cnt == 0)
|
if (--m_hb_tx_cnt == 0)
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ class SatelliteClient : public sigc::trackable
|
|||||||
void sendNodeList(
|
void sendNodeList(
|
||||||
const std::vector<MsgPeerNodeList::NodeEntry>& nodes);
|
const std::vector<MsgPeerNodeList::NodeEntry>& 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
|
// Read-only access to the parent's combined-view roster, surfaced
|
||||||
// by Reflector::statusJson under /status.parent.nodes.
|
// by Reflector::statusJson under /status.parent.nodes.
|
||||||
const std::vector<MsgPeerNodeList::NodeEntry>& parentNodes(void) const
|
const std::vector<MsgPeerNodeList::NodeEntry>& parentNodes(void) const
|
||||||
@@ -96,6 +104,10 @@ class SatelliteClient : public sigc::trackable
|
|||||||
void handleMsgPeerFlush(std::istream& is);
|
void handleMsgPeerFlush(std::istream& is);
|
||||||
void handleMsgPeerHeartbeat(void);
|
void handleMsgPeerHeartbeat(void);
|
||||||
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);
|
||||||
void sendMsg(const ReflectorMsg& msg);
|
void sendMsg(const ReflectorMsg& msg);
|
||||||
void sendFilter(void);
|
void sendFilter(void);
|
||||||
void heartbeatTick(Async::Timer* t);
|
void heartbeatTick(Async::Timer* t);
|
||||||
|
|||||||
Reference in new issue
Block a user