twin: expose partner roster in /status (fixes #3)
Reflector::refreshStatus() now emits a m_status["twin"] object (host, port, connection/hello state, prefix, peer_id, priorities) mirroring the existing trunks[] pattern. To populate the partner's connected-stations list, TwinLink now carries MsgTrunkNodeList (type 121) over the [TWIN] socket — reusing the trunk wire message, no new protocol type. Local roster changes flow via Reflector::sendNodeListToAllPeers() -> TwinLink::onLocalNodeListUpdated(); incoming lists are sanitized and cached in m_partner_nodes, surfaced as twin.nodes. Without this, [TWIN]-paired reflectors could not observe each other's rosters from /status — the data was not on the wire at all (TwinLink only carried talker state).
This commit is contained in:
1 parent
4bbd53172a
commit
fa6f137e1c
4 files changed
+214
-2
No files matched your search
@@ -1678,6 +1678,15 @@ void Reflector::refreshStatus(void)
|
||||
}
|
||||
m_status["trunks"] = trunks;
|
||||
|
||||
if (m_twin_link != nullptr)
|
||||
{
|
||||
m_status["twin"] = m_twin_link->statusJson();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_status.removeMember("twin");
|
||||
}
|
||||
|
||||
Json::Value cluster_arr(Json::arrayValue);
|
||||
for (uint32_t tg : m_cluster_tgs)
|
||||
{
|
||||
@@ -3133,6 +3142,11 @@ void Reflector::sendNodeListToAllPeers(void)
|
||||
link->sendNodeList(nodes);
|
||||
}
|
||||
|
||||
if (m_twin_link != nullptr)
|
||||
{
|
||||
m_twin_link->onLocalNodeListUpdated(nodes);
|
||||
}
|
||||
|
||||
if (m_mqtt != nullptr)
|
||||
{
|
||||
m_mqtt->publishLocalNodes(nodes);
|
||||
|
||||
@@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
@@ -70,6 +71,44 @@ using namespace Async;
|
||||
using namespace sigc;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// Byte-bound and strip control chars / ':' from an identifier coming over
|
||||
// the wire. Matches the sanitizer used in TrunkLink for node-list entries;
|
||||
// the twin partner is HMAC-authenticated but wire data still flows into
|
||||
// logs and /status JSON, so keep the same hygiene.
|
||||
std::string sanitizeIdent(const std::string& in, size_t max_len)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(std::min(in.size(), max_len));
|
||||
for (char c : in)
|
||||
{
|
||||
unsigned char u = static_cast<unsigned char>(c);
|
||||
if (u < 0x20 || u == 0x7f) continue;
|
||||
if (c == ':') continue;
|
||||
out += c;
|
||||
if (out.size() >= max_len) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string sanitizeText(const std::string& in, size_t max_bytes)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(std::min(in.size(), max_bytes));
|
||||
for (char c : in)
|
||||
{
|
||||
unsigned char u = static_cast<unsigned char>(c);
|
||||
if (u < 0x20 || u == 0x7f) continue;
|
||||
out += c;
|
||||
if (out.size() >= max_bytes) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} /* anonymous namespace */
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* TwinLink public methods
|
||||
@@ -268,6 +307,14 @@ void TwinLink::onExternalTrunkTalkerStop(uint32_t tg,
|
||||
} /* TwinLink::onExternalTrunkTalkerStop */
|
||||
|
||||
|
||||
void TwinLink::onLocalNodeListUpdated(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes)
|
||||
{
|
||||
if (!isActive()) return;
|
||||
sendMsg(MsgTrunkNodeList(nodes));
|
||||
} /* TwinLink::onLocalNodeListUpdated */
|
||||
|
||||
|
||||
bool TwinLink::isActive(void) const
|
||||
{
|
||||
return (m_con.isConnected() && m_ob_hello_received) ||
|
||||
@@ -275,6 +322,41 @@ bool TwinLink::isActive(void) const
|
||||
} /* TwinLink::isActive */
|
||||
|
||||
|
||||
Json::Value TwinLink::statusJson(void) const
|
||||
{
|
||||
Json::Value obj(Json::objectValue);
|
||||
obj["host"] = m_peer_host;
|
||||
obj["port"] = m_peer_port;
|
||||
obj["connected"] = isActive();
|
||||
obj["outbound_connected"] = m_con.isConnected();
|
||||
obj["outbound_hello"] = m_ob_hello_received;
|
||||
obj["inbound_connected"] = (m_inbound_con != nullptr);
|
||||
obj["inbound_hello"] = m_ib_hello_received;
|
||||
obj["local_prefix"] = m_local_prefix;
|
||||
obj["peer_id"] = m_peer_id_received;
|
||||
obj["priority"] = static_cast<Json::UInt>(m_priority);
|
||||
obj["peer_priority"] = static_cast<Json::UInt>(m_peer_priority);
|
||||
|
||||
Json::Value nodes_arr(Json::arrayValue);
|
||||
for (const auto& n : m_partner_nodes)
|
||||
{
|
||||
Json::Value entry(Json::objectValue);
|
||||
entry["callsign"] = n.callsign;
|
||||
entry["tg"] = static_cast<Json::UInt>(n.tg);
|
||||
if (n.lat != 0.0f || n.lon != 0.0f)
|
||||
{
|
||||
entry["lat"] = n.lat;
|
||||
entry["lon"] = n.lon;
|
||||
}
|
||||
if (!n.qth_name.empty()) entry["qth_name"] = n.qth_name;
|
||||
nodes_arr.append(entry);
|
||||
}
|
||||
obj["nodes"] = nodes_arr;
|
||||
|
||||
return obj;
|
||||
} /* TwinLink::statusJson */
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* TwinLink private methods
|
||||
@@ -370,6 +452,9 @@ void TwinLink::onFrameReceived(FramedTcpConnection* con,
|
||||
case MsgTrunkFlush::TYPE:
|
||||
handleMsgTrunkFlush(ss);
|
||||
break;
|
||||
case MsgTrunkNodeList::TYPE:
|
||||
handleMsgTrunkNodeList(ss);
|
||||
break;
|
||||
case MsgTwinExtTalkerStart::TYPE:
|
||||
handleMsgTwinExtTalkerStart(ss);
|
||||
break;
|
||||
@@ -529,6 +614,48 @@ void TwinLink::handleMsgTwinExtTalkerStop(std::istream& is)
|
||||
} /* TwinLink::handleMsgTwinExtTalkerStop */
|
||||
|
||||
|
||||
void TwinLink::handleMsgTrunkNodeList(std::istream& is)
|
||||
{
|
||||
MsgTrunkNodeList msg;
|
||||
if (!msg.unpack(is))
|
||||
{
|
||||
geulog::error("twin", "TWIN: Failed to unpack MsgTrunkNodeList");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> sanitized;
|
||||
sanitized.reserve(msg.nodes().size());
|
||||
unsigned dropped = 0;
|
||||
for (const auto& n : msg.nodes())
|
||||
{
|
||||
MsgTrunkNodeList::NodeEntry e;
|
||||
e.callsign = sanitizeIdent(n.callsign, 32);
|
||||
if (e.callsign.empty())
|
||||
{
|
||||
++dropped;
|
||||
continue;
|
||||
}
|
||||
e.tg = n.tg;
|
||||
e.qth_name = sanitizeText(n.qth_name, 64);
|
||||
if (std::isfinite(n.lat) && std::isfinite(n.lon) &&
|
||||
n.lat >= -90.0f && n.lat <= 90.0f &&
|
||||
n.lon >= -180.0f && n.lon <= 180.0f)
|
||||
{
|
||||
e.lat = n.lat;
|
||||
e.lon = n.lon;
|
||||
}
|
||||
sanitized.push_back(std::move(e));
|
||||
}
|
||||
if (dropped > 0)
|
||||
{
|
||||
geulog::warn("twin", "TWIN: dropped ", dropped,
|
||||
" node list entrie(s) with empty/invalid callsign");
|
||||
}
|
||||
|
||||
m_partner_nodes = std::move(sanitized);
|
||||
} /* TwinLink::handleMsgTrunkNodeList */
|
||||
|
||||
|
||||
void TwinLink::heartbeatTick(Async::Timer* /*t*/)
|
||||
{
|
||||
// Outbound heartbeat
|
||||
|
||||
@@ -43,6 +43,8 @@ logic — the pair shares everything.
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include <json/json.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
@@ -56,6 +58,15 @@ logic — the pair shares everything.
|
||||
#include <AsyncTimer.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Local Includes
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "ReflectorMsg.h"
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Forward declarations
|
||||
@@ -63,8 +74,6 @@ logic — the pair shares everything.
|
||||
****************************************************************************/
|
||||
|
||||
class Reflector;
|
||||
class MsgTrunkHello;
|
||||
class ReflectorMsg;
|
||||
|
||||
class TwinLink
|
||||
{
|
||||
@@ -92,12 +101,19 @@ class TwinLink
|
||||
void onExternalTrunkTalkerStop(uint32_t tg,
|
||||
const std::string& peer_id);
|
||||
|
||||
// Called by Reflector when the local node roster changes, to mirror
|
||||
// our connected-stations list to the twin partner.
|
||||
void onLocalNodeListUpdated(
|
||||
const std::vector<MsgTrunkNodeList::NodeEntry>& nodes);
|
||||
|
||||
bool isActive(void) const;
|
||||
const std::string& partnerHost(void) const { return m_peer_host; }
|
||||
uint16_t partnerPort(void) const { return m_peer_port; }
|
||||
const std::string& secret(void) const { return m_secret; }
|
||||
const std::string& localPrefix(void) const { return m_local_prefix; }
|
||||
|
||||
Json::Value statusJson(void) const;
|
||||
|
||||
private:
|
||||
using FramedTcpClient =
|
||||
Async::TcpPrioClient<Async::FramedTcpConnection>;
|
||||
@@ -124,6 +140,7 @@ class TwinLink
|
||||
bool m_ib_hello_received;
|
||||
unsigned m_ib_hb_tx_cnt;
|
||||
unsigned m_ib_hb_rx_cnt;
|
||||
std::vector<MsgTrunkNodeList::NodeEntry> m_partner_nodes;
|
||||
|
||||
// No copy
|
||||
TwinLink(const TwinLink&);
|
||||
@@ -140,6 +157,7 @@ class TwinLink
|
||||
void handleMsgTrunkAudio(std::istream& is);
|
||||
void handleMsgTrunkFlush(std::istream& is);
|
||||
void handleMsgTrunkHeartbeat(void);
|
||||
void handleMsgTrunkNodeList(std::istream& is);
|
||||
void handleMsgTwinExtTalkerStart(std::istream& is);
|
||||
void handleMsgTwinExtTalkerStop(std::istream& is);
|
||||
void heartbeatTick(Async::Timer*);
|
||||
|
||||
Reference in new issue
Block a user