Merge /config into /status and remove /config endpoint
All static configuration fields (version, local_prefix, listen_port, http_port, mode, satellite/satellite_server) are now included directly in the /status JSON response. The /config endpoint is removed.
This commit is contained in:
1 parent
c82827080c
commit
4e6bff7962
4 files changed
+69
-147
No files matched your search
@@ -52,7 +52,7 @@ automatically.
|
|||||||
- **Satellite reflectors** — lightweight relay instances that connect to a parent
|
- **Satellite reflectors** — lightweight relay instances that connect to a parent
|
||||||
reflector instead of joining the full mesh, reducing configuration overhead for
|
reflector instead of joining the full mesh, reducing configuration overhead for
|
||||||
large deployments
|
large deployments
|
||||||
- **HTTP `/status` and `/config` endpoints** — JSON status with trunk state,
|
- **HTTP `/status` endpoint** — JSON status with trunk state,
|
||||||
active talkers, satellite connections, and static configuration
|
active talkers, satellite connections, and static configuration
|
||||||
- SvxLink client nodes are **unmodified** — they connect to their local
|
- SvxLink client nodes are **unmodified** — they connect to their local
|
||||||
reflector as normal and are unaware of the trunk
|
reflector as normal and are unaware of the trunk
|
||||||
@@ -293,14 +293,20 @@ trunk port `5302`).
|
|||||||
|
|
||||||
## HTTP Status
|
## HTTP Status
|
||||||
|
|
||||||
Enable with `HTTP_SRV_PORT=8080` in `[GLOBAL]`. Two endpoints are available:
|
Enable with `HTTP_SRV_PORT=8080` in `[GLOBAL]`.
|
||||||
|
|
||||||
### `GET /status` — live state
|
### `GET /status`
|
||||||
|
|
||||||
Returns nodes, trunk connection state, and active talkers:
|
Returns live state (nodes, trunk connections, active talkers, satellites) and
|
||||||
|
static configuration in a single response:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"mode": "reflector",
|
||||||
|
"local_prefix": ["1"],
|
||||||
|
"listen_port": "5300",
|
||||||
|
"http_port": "8080",
|
||||||
"nodes": { ... },
|
"nodes": { ... },
|
||||||
"cluster_tgs": [222, 2221, 91],
|
"cluster_tgs": [222, 2221, 91],
|
||||||
"trunks": {
|
"trunks": {
|
||||||
@@ -322,31 +328,6 @@ Returns nodes, trunk connection state, and active talkers:
|
|||||||
"authenticated": true,
|
"authenticated": true,
|
||||||
"active_tgs": [1, 100]
|
"active_tgs": [1, 100]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`active_talkers` lists TGs with an active remote talker at query time (both
|
|
||||||
prefix-based and cluster TGs). `satellites` appears only when satellites are
|
|
||||||
connected.
|
|
||||||
|
|
||||||
### `GET /config` — static configuration
|
|
||||||
|
|
||||||
Returns the reflector's own configuration, useful for dashboards:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"mode": "reflector",
|
|
||||||
"local_prefix": ["1"],
|
|
||||||
"cluster_tgs": [222, 2221, 91],
|
|
||||||
"listen_port": "5300",
|
|
||||||
"http_port": "8080",
|
|
||||||
"trunks": {
|
|
||||||
"TRUNK_2": {
|
|
||||||
"host": "reflector-b.example.com",
|
|
||||||
"port": 5302,
|
|
||||||
"remote_prefix": ["2"]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"satellite_server": {
|
"satellite_server": {
|
||||||
"listen_port": "5303",
|
"listen_port": "5303",
|
||||||
@@ -355,19 +336,9 @@ Returns the reflector's own configuration, useful for dashboards:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
When running in satellite mode:
|
`active_talkers` lists TGs with an active remote talker at query time (both
|
||||||
|
prefix-based and cluster TGs). `satellites` and `satellite_server` appear only
|
||||||
```json
|
when applicable.
|
||||||
{
|
|
||||||
"mode": "satellite",
|
|
||||||
"listen_port": "5300",
|
|
||||||
"satellite": {
|
|
||||||
"parent_host": "reflector-01.example.com",
|
|
||||||
"parent_port": "5303",
|
|
||||||
"id": "my-satellite"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -65,7 +65,7 @@ TRUNK_2: Trunk hello from peer 'TRUNK_1' local_prefix=2 priority=3847291042
|
|||||||
| 5300 | UDP | SvxLink client audio |
|
| 5300 | UDP | SvxLink client audio |
|
||||||
| 5302 | TCP | Server-to-server trunk links |
|
| 5302 | TCP | Server-to-server trunk links |
|
||||||
| 5303 | TCP | Satellite connections (optional) |
|
| 5303 | TCP | Satellite connections (optional) |
|
||||||
| 8080 | TCP | HTTP `/status` and `/config` endpoints (optional) |
|
| 8080 | TCP | HTTP `/status` endpoint (optional) |
|
||||||
|
|
||||||
If you do not set `HTTP_SRV_PORT` in the config, remove the `8080` port mapping
|
If you do not set `HTTP_SRV_PORT` in the config, remove the `8080` port mapping
|
||||||
from `docker-compose.yml`.
|
from `docker-compose.yml`.
|
||||||
|
|||||||
@@ -1538,104 +1538,6 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.target == "/config")
|
|
||||||
{
|
|
||||||
Json::Value cfg_json(Json::objectValue);
|
|
||||||
cfg_json["version"] = SVXREFLECTOR_VERSION;
|
|
||||||
|
|
||||||
// Local prefixes
|
|
||||||
std::string local_prefix_str;
|
|
||||||
m_cfg->getValue("GLOBAL", "LOCAL_PREFIX", local_prefix_str);
|
|
||||||
Json::Value lp_arr(Json::arrayValue);
|
|
||||||
{
|
|
||||||
std::istringstream ss(local_prefix_str);
|
|
||||||
std::string token;
|
|
||||||
while (std::getline(ss, token, ','))
|
|
||||||
{
|
|
||||||
token.erase(0, token.find_first_not_of(" \t"));
|
|
||||||
token.erase(token.find_last_not_of(" \t") + 1);
|
|
||||||
if (!token.empty()) lp_arr.append(token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cfg_json["local_prefix"] = lp_arr;
|
|
||||||
|
|
||||||
// Cluster TGs
|
|
||||||
Json::Value cluster_arr(Json::arrayValue);
|
|
||||||
for (uint32_t tg : m_cluster_tgs)
|
|
||||||
{
|
|
||||||
cluster_arr.append(tg);
|
|
||||||
}
|
|
||||||
cfg_json["cluster_tgs"] = cluster_arr;
|
|
||||||
|
|
||||||
// Trunk peers (static config)
|
|
||||||
Json::Value peers(Json::objectValue);
|
|
||||||
for (auto* link : m_trunk_links)
|
|
||||||
{
|
|
||||||
Json::Value peer(Json::objectValue);
|
|
||||||
Json::Value link_status = link->statusJson();
|
|
||||||
peer["host"] = link_status["host"];
|
|
||||||
peer["port"] = link_status["port"];
|
|
||||||
peer["remote_prefix"] = link_status["remote_prefix"];
|
|
||||||
peers[link->section()] = peer;
|
|
||||||
}
|
|
||||||
cfg_json["trunks"] = peers;
|
|
||||||
|
|
||||||
// Listen port
|
|
||||||
std::string listen_port("5300");
|
|
||||||
m_cfg->getValue("GLOBAL", "LISTEN_PORT", listen_port);
|
|
||||||
cfg_json["listen_port"] = listen_port;
|
|
||||||
|
|
||||||
// HTTP port
|
|
||||||
std::string http_port;
|
|
||||||
if (m_cfg->getValue("GLOBAL", "HTTP_SRV_PORT", http_port))
|
|
||||||
{
|
|
||||||
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";
|
|
||||||
builder["indentation"] = "";
|
|
||||||
Json::StreamWriter* writer = builder.newStreamWriter();
|
|
||||||
writer->write(cfg_json, &os);
|
|
||||||
delete writer;
|
|
||||||
|
|
||||||
res.setContent("application/json", os.str());
|
|
||||||
res.setSendContent(req.method == "GET");
|
|
||||||
res.setCode(200);
|
|
||||||
con->write(res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.target != "/status")
|
if (req.target != "/status")
|
||||||
{
|
{
|
||||||
res.setCode(404);
|
res.setCode(404);
|
||||||
@@ -1687,6 +1589,61 @@ void Reflector::httpRequestReceived(Async::HttpServerConnection *con,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Static configuration
|
||||||
|
m_status["version"] = SVXREFLECTOR_VERSION;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string local_prefix_str;
|
||||||
|
m_cfg->getValue("GLOBAL", "LOCAL_PREFIX", local_prefix_str);
|
||||||
|
Json::Value lp_arr(Json::arrayValue);
|
||||||
|
std::istringstream ss(local_prefix_str);
|
||||||
|
std::string token;
|
||||||
|
while (std::getline(ss, token, ','))
|
||||||
|
{
|
||||||
|
token.erase(0, token.find_first_not_of(" \t"));
|
||||||
|
token.erase(token.find_last_not_of(" \t") + 1);
|
||||||
|
if (!token.empty()) lp_arr.append(token);
|
||||||
|
}
|
||||||
|
m_status["local_prefix"] = lp_arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string listen_port("5300");
|
||||||
|
m_cfg->getValue("GLOBAL", "LISTEN_PORT", listen_port);
|
||||||
|
m_status["listen_port"] = listen_port;
|
||||||
|
|
||||||
|
std::string http_port;
|
||||||
|
if (m_cfg->getValue("GLOBAL", "HTTP_SRV_PORT", http_port))
|
||||||
|
{
|
||||||
|
m_status["http_port"] = http_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_is_satellite)
|
||||||
|
{
|
||||||
|
m_status["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;
|
||||||
|
m_status["satellite"] = sat_cfg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_status["mode"] = "reflector";
|
||||||
|
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());
|
||||||
|
m_status["satellite_server"] = sat_srv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
Json::StreamWriterBuilder builder;
|
Json::StreamWriterBuilder builder;
|
||||||
builder["commentStyle"] = "None";
|
builder["commentStyle"] = "None";
|
||||||
|
|||||||
@@ -485,12 +485,6 @@ def get_status(host: str, port: int, timeout: float = 3.0) -> dict:
|
|||||||
return json.loads(resp.read())
|
return json.loads(resp.read())
|
||||||
|
|
||||||
|
|
||||||
def get_config(host: str, port: int, timeout: float = 3.0) -> dict:
|
|
||||||
url = f"http://{host}:{port}/config"
|
|
||||||
with urlopen(url, timeout=timeout) as resp:
|
|
||||||
return json.loads(resp.read())
|
|
||||||
|
|
||||||
|
|
||||||
def wait_until(predicate, timeout: float = 10.0, interval: float = 0.2,
|
def wait_until(predicate, timeout: float = 10.0, interval: float = 0.2,
|
||||||
msg: str = "condition not met"):
|
msg: str = "condition not met"):
|
||||||
"""Poll predicate() until it returns True or timeout expires."""
|
"""Poll predicate() until it returns True or timeout expires."""
|
||||||
|
|||||||
Reference in new issue
Block a user