feat(twin): add MsgPeerClient* send/receive on TwinLink
Twin pairs gain symmetric per-client liveness deltas — each twin's broker now emits peer/<twin_id>/client/<call>/<event> for the other twin's clients. Also plumbs peer_id through TwinLink::handleMsgPeerTalkerStart (switching from setTrunkTalkerForTG to setTrunkTalkerForTGViaPeer with m_peer_id_config), closing the deferred fix from Task 6.5 and ensuring peer/<twin_id>/talker/<tg>/start fires correctly.
This commit is contained in:
1 parent
1bb847b3c8
commit
6f407a5a77
2 files changed
+156
-3
No files matched your search
@@ -507,6 +507,18 @@ void TwinLink::onFrameReceived(FramedTcpConnection* con,
|
||||
case MsgTwinExtTalkerStop::TYPE:
|
||||
handleMsgTwinExtTalkerStop(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:
|
||||
// Unknown / not-yet-implemented types silently ignored for now
|
||||
break;
|
||||
@@ -574,9 +586,12 @@ void TwinLink::handleMsgPeerTalkerStart(std::istream& is)
|
||||
geulog::error("twin", "TWIN: Failed to unpack MsgPeerTalkerStart");
|
||||
return;
|
||||
}
|
||||
// setTrunkTalkerForTG fires trunkTalkerUpdated → onTrunkTalkerUpdated in
|
||||
// Reflector, which broadcasts MsgTalkerStart to all local clients on this TG.
|
||||
TGHandler::instance()->setTrunkTalkerForTG(msg.tg(), msg.callsign());
|
||||
// setTrunkTalkerForTGViaPeer records peer attribution and fires
|
||||
// trunkTalkerUpdated → onTrunkTalkerUpdated in Reflector, which broadcasts
|
||||
// MsgTalkerStart to all local clients on this TG and emits the correct
|
||||
// peer/<twin_id>/talker/<tg>/start MQTT topic.
|
||||
TGHandler::instance()->setTrunkTalkerForTGViaPeer(
|
||||
msg.tg(), msg.callsign(), m_peer_id_config);
|
||||
} /* TwinLink::handleMsgPeerTalkerStart */
|
||||
|
||||
|
||||
@@ -814,6 +829,131 @@ void TwinLink::sendMsgOnInbound(const ReflectorMsg& msg)
|
||||
} /* TwinLink::sendMsgOnInbound */
|
||||
|
||||
|
||||
void TwinLink::sendClientConnected(const std::string& callsign,
|
||||
uint32_t tg,
|
||||
const std::string& ip)
|
||||
{
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgPeerClientConnected(callsign, tg, ip));
|
||||
} /* TwinLink::sendClientConnected */
|
||||
|
||||
|
||||
void TwinLink::sendClientDisconnected(const std::string& callsign)
|
||||
{
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgPeerClientDisconnected(callsign));
|
||||
} /* TwinLink::sendClientDisconnected */
|
||||
|
||||
|
||||
void TwinLink::sendClientRx(const std::string& callsign,
|
||||
const std::string& rx_json)
|
||||
{
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgPeerClientRx(callsign, rx_json));
|
||||
} /* TwinLink::sendClientRx */
|
||||
|
||||
|
||||
void TwinLink::sendClientStatus(const std::string& callsign,
|
||||
const std::string& status_json)
|
||||
{
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgPeerClientStatus(callsign, status_json));
|
||||
} /* TwinLink::sendClientStatus */
|
||||
|
||||
|
||||
void TwinLink::handleMsgPeerClientConnected(std::istream& is)
|
||||
{
|
||||
MsgPeerClientConnected msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("twin",
|
||||
"Failed to unpack MsgPeerClientConnected from twin '",
|
||||
m_peer_id_config, "'");
|
||||
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_peer_id_config, msg.callsign(), "connected", payload, false);
|
||||
}
|
||||
} /* TwinLink::handleMsgPeerClientConnected */
|
||||
|
||||
|
||||
void TwinLink::handleMsgPeerClientDisconnected(std::istream& is)
|
||||
{
|
||||
MsgPeerClientDisconnected msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("twin",
|
||||
"Failed to unpack MsgPeerClientDisconnected from twin '",
|
||||
m_peer_id_config, "'");
|
||||
return;
|
||||
}
|
||||
Json::Value payload(Json::objectValue);
|
||||
if (m_reflector->mqtt() != nullptr)
|
||||
{
|
||||
m_reflector->mqtt()->publishPeerClientEvent(
|
||||
m_peer_id_config, msg.callsign(), "disconnected", payload, false);
|
||||
}
|
||||
} /* TwinLink::handleMsgPeerClientDisconnected */
|
||||
|
||||
|
||||
void TwinLink::handleMsgPeerClientRx(std::istream& is)
|
||||
{
|
||||
MsgPeerClientRx msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("twin",
|
||||
"Failed to unpack MsgPeerClientRx from twin '", m_peer_id_config, "'");
|
||||
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_peer_id_config, msg.callsign(), "rx", rx_json, true); // retained
|
||||
}
|
||||
} /* TwinLink::handleMsgPeerClientRx */
|
||||
|
||||
|
||||
void TwinLink::handleMsgPeerClientStatus(std::istream& is)
|
||||
{
|
||||
MsgPeerClientStatus msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("twin",
|
||||
"Failed to unpack MsgPeerClientStatus from twin '",
|
||||
m_peer_id_config, "'");
|
||||
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_peer_id_config, msg.callsign(), "status", status_json, true); // retained
|
||||
}
|
||||
} /* TwinLink::handleMsgPeerClientStatus */
|
||||
|
||||
|
||||
/*
|
||||
* This file has not been truncated
|
||||
*/
|
||||
@@ -106,6 +106,15 @@ class TwinLink
|
||||
void onLocalNodeListUpdated(
|
||||
const std::vector<MsgPeerNodeList::NodeEntry>& nodes);
|
||||
|
||||
// Per-client liveness deltas — mirrored symmetrically to twin partner
|
||||
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);
|
||||
|
||||
bool isActive(void) const;
|
||||
const std::string& partnerHost(void) const { return m_peer_host; }
|
||||
uint16_t partnerPort(void) const { return m_peer_port; }
|
||||
@@ -166,6 +175,10 @@ class TwinLink
|
||||
void clearPartnerRosterIfInactive(void);
|
||||
void handleMsgTwinExtTalkerStart(std::istream& is);
|
||||
void handleMsgTwinExtTalkerStop(std::istream& is);
|
||||
void handleMsgPeerClientConnected(std::istream& is);
|
||||
void handleMsgPeerClientDisconnected(std::istream& is);
|
||||
void handleMsgPeerClientRx(std::istream& is);
|
||||
void handleMsgPeerClientStatus(std::istream& is);
|
||||
void heartbeatTick(Async::Timer*);
|
||||
|
||||
bool sendMsg(const ReflectorMsg& msg);
|
||||
|
||||
Reference in new issue
Block a user