mirror of
https://github.com/daeuniverse/honk.git
synced 2026-12-06 08:02:27 +00:00
Merge pull request #143 from Zakkaus/fix/subscription-userinfo
fix(subscription): report provider usage and expiry
This commit is contained in:
13 files changed
+162
-28
No files matched your search
@@ -331,6 +331,7 @@ pub(crate) struct Reply {
|
||||
pub(crate) status: http::StatusCode,
|
||||
/// Unchecked, so a caller that follows it can reject one that is not text.
|
||||
pub(crate) location: Option<http::HeaderValue>,
|
||||
pub(crate) subscription_userinfo: Option<http::HeaderValue>,
|
||||
pub(crate) body: Arc<[u8]>,
|
||||
}
|
||||
|
||||
@@ -367,10 +368,12 @@ pub(crate) async fn read(
|
||||
let result = async {
|
||||
let status = parts.status;
|
||||
let location = parts.headers.get(LOCATION).cloned();
|
||||
let subscription_userinfo = parts.headers.get("subscription-userinfo").cloned();
|
||||
if !wants_body(status, &parts.headers) {
|
||||
return Ok(Reply {
|
||||
status,
|
||||
location,
|
||||
subscription_userinfo,
|
||||
body: Arc::from([]),
|
||||
});
|
||||
}
|
||||
@@ -420,12 +423,14 @@ pub(crate) async fn read(
|
||||
Some(buffer) if buffer.len() == received => Ok(Reply {
|
||||
status,
|
||||
location,
|
||||
subscription_userinfo,
|
||||
body: buffer,
|
||||
}),
|
||||
Some(_) => Err("http_failed".into()),
|
||||
None => Ok(Reply {
|
||||
status,
|
||||
location,
|
||||
subscription_userinfo,
|
||||
body: grown.into(),
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ pub(crate) struct Provider {
|
||||
node_count: usize,
|
||||
updated_at: Option<String>,
|
||||
expires_at: Option<String>,
|
||||
traffic: Option<()>,
|
||||
traffic: Option<ProviderTraffic>,
|
||||
status: &'static str,
|
||||
last_error: Option<ProviderError>,
|
||||
download: Option<Value>,
|
||||
@@ -58,6 +58,13 @@ impl std::fmt::Debug for Provider {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize)]
|
||||
struct ProviderTraffic {
|
||||
upload_bytes: Option<String>,
|
||||
download_bytes: Option<String>,
|
||||
total_bytes: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
struct ProviderError {
|
||||
code: &'static str,
|
||||
@@ -105,8 +112,19 @@ impl Provider {
|
||||
url_redacted: Some(subscription.url.clone()),
|
||||
node_count,
|
||||
updated_at: load.updated_at.map(timestamp),
|
||||
expires_at: None,
|
||||
traffic: None,
|
||||
expires_at: load
|
||||
.userinfo
|
||||
.expire
|
||||
.and_then(|seconds| chrono::DateTime::from_timestamp(seconds.try_into().ok()?, 0))
|
||||
.map(|expires| timestamp(expires.into())),
|
||||
traffic: (load.userinfo.upload.is_some()
|
||||
|| load.userinfo.download.is_some()
|
||||
|| load.userinfo.total.is_some())
|
||||
.then(|| ProviderTraffic {
|
||||
upload_bytes: load.userinfo.upload.map(|bytes| bytes.to_string()),
|
||||
download_bytes: load.userinfo.download.map(|bytes| bytes.to_string()),
|
||||
total_bytes: load.userinfo.total.map(|bytes| bytes.to_string()),
|
||||
}),
|
||||
status: if load.error.is_some() && node_count == 0 {
|
||||
"error"
|
||||
} else if load.updated_at.is_none()
|
||||
@@ -165,6 +183,12 @@ impl Provider {
|
||||
+ self.name.capacity()
|
||||
+ self.url_redacted.as_ref().map_or(0, String::capacity)
|
||||
+ self.updated_at.as_ref().map_or(0, String::capacity)
|
||||
+ self.expires_at.as_ref().map_or(0, String::capacity)
|
||||
+ self.traffic.as_ref().map_or(0, |traffic| {
|
||||
traffic.upload_bytes.as_ref().map_or(0, String::capacity)
|
||||
+ traffic.download_bytes.as_ref().map_or(0, String::capacity)
|
||||
+ traffic.total_bytes.as_ref().map_or(0, String::capacity)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,15 @@ async fn provider_get_is_safe_pure_and_counts_accepted_provenance_not_display_na
|
||||
assert!(detail["updated_at"].is_string());
|
||||
assert_eq!(detail["url_redacted"], subscription.url);
|
||||
assert_eq!(detail["name"], subscription.name);
|
||||
assert!(detail["traffic"].is_null() && detail["expires_at"].is_null());
|
||||
assert_eq!(
|
||||
detail["traffic"],
|
||||
json!({
|
||||
"upload_bytes": "422986054",
|
||||
"download_bytes": "5198408536",
|
||||
"total_bytes": "214748364800",
|
||||
})
|
||||
);
|
||||
assert_eq!(detail["expires_at"], "2026-12-08T06:54:09.000Z");
|
||||
assert_eq!(
|
||||
list["providers"]
|
||||
.as_array()
|
||||
|
||||
@@ -65,7 +65,7 @@ pub(super) async fn respond(mut socket: TcpStream, body: &str) {
|
||||
socket
|
||||
.write_all(
|
||||
format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
||||
"HTTP/1.1 200 OK\r\nsubscription-userinfo: upload=422986054; download=5198408536; total=214748364800; expire=1796712849\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
||||
body.len()
|
||||
)
|
||||
.as_bytes(),
|
||||
|
||||
@@ -366,10 +366,38 @@ fn subscription_client() -> anyhow::Result<crate::marked_http::Client> {
|
||||
crate::marked_http::Client::new()
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub(crate) struct SubscriptionUserinfo {
|
||||
pub(crate) upload: Option<u64>,
|
||||
pub(crate) download: Option<u64>,
|
||||
pub(crate) total: Option<u64>,
|
||||
pub(crate) expire: Option<u64>,
|
||||
}
|
||||
|
||||
fn parse_subscription_userinfo(header: &str) -> SubscriptionUserinfo {
|
||||
let mut userinfo = SubscriptionUserinfo::default();
|
||||
for pair in header.split(';') {
|
||||
let Some((key, value)) = pair.split_once('=') else {
|
||||
continue;
|
||||
};
|
||||
let Ok(value) = value.trim().parse::<u64>() else {
|
||||
continue;
|
||||
};
|
||||
match key.trim() {
|
||||
"upload" => userinfo.upload = Some(value),
|
||||
"download" => userinfo.download = Some(value),
|
||||
"total" => userinfo.total = (value != 0).then_some(value),
|
||||
"expire" => userinfo.expire = (value != 0).then_some(value),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
userinfo
|
||||
}
|
||||
|
||||
async fn fetch_body(
|
||||
client: &crate::marked_http::Client,
|
||||
sub: &Subscription,
|
||||
) -> anyhow::Result<Vec<u8>> {
|
||||
) -> anyhow::Result<(Vec<u8>, SubscriptionUserinfo)> {
|
||||
fetch_following(sub, route::Hop::Direct(client)).await
|
||||
}
|
||||
|
||||
@@ -392,7 +420,10 @@ fn subscription_request_headers(sub: &Subscription) -> anyhow::Result<http::Head
|
||||
/// Fetches the subscription over `hop`, direct or routed alike. Redirects
|
||||
/// are followed here, not by the client, so each hop is checked against the
|
||||
/// original origin and cross-origin hops drop credentials.
|
||||
async fn fetch_following(sub: &Subscription, hop: route::Hop<'_>) -> anyhow::Result<Vec<u8>> {
|
||||
async fn fetch_following(
|
||||
sub: &Subscription,
|
||||
hop: route::Hop<'_>,
|
||||
) -> anyhow::Result<(Vec<u8>, SubscriptionUserinfo)> {
|
||||
let deadline = tokio::time::Instant::now() + SUBSCRIPTION_TIMEOUT;
|
||||
let mut url = reqwest::Url::parse(&sub.url)?;
|
||||
let mut headers = subscription_request_headers(sub)?;
|
||||
@@ -426,7 +457,13 @@ async fn fetch_following(sub: &Subscription, hop: route::Hop<'_>) -> anyhow::Res
|
||||
"subscription server answered HTTP {}",
|
||||
reply.status
|
||||
);
|
||||
return Ok(reply.body.to_vec());
|
||||
let userinfo = reply
|
||||
.subscription_userinfo
|
||||
.as_ref()
|
||||
.and_then(|header| header.to_str().ok())
|
||||
.map(parse_subscription_userinfo)
|
||||
.unwrap_or_default();
|
||||
return Ok((reply.body.to_vec(), userinfo));
|
||||
}
|
||||
unreachable!("redirect bound checked before following");
|
||||
}
|
||||
@@ -500,7 +537,7 @@ impl SubscriptionManager {
|
||||
diagnostics: &mut Vec<DetailedDiagnostic>,
|
||||
) -> anyhow::Result<Vec<Node>> {
|
||||
let start = diagnostics.len();
|
||||
let (nodes, content) = self.fetch_content(sub, diagnostics).await?;
|
||||
let (nodes, content, _) = self.fetch_content(sub, diagnostics).await?;
|
||||
Self::persist_content(sub, store, content, diagnostics, start).await;
|
||||
Ok(nodes)
|
||||
}
|
||||
@@ -509,8 +546,8 @@ impl SubscriptionManager {
|
||||
&self,
|
||||
sub: &Subscription,
|
||||
diagnostics: &mut Vec<DetailedDiagnostic>,
|
||||
) -> anyhow::Result<(Vec<Node>, String)> {
|
||||
let body = if route::direct(sub) {
|
||||
) -> anyhow::Result<(Vec<Node>, String, SubscriptionUserinfo)> {
|
||||
let (body, userinfo) = if route::direct(sub) {
|
||||
match &self.http {
|
||||
SubscriptionHttp::Shared(client) => fetch_body(client, sub).await?,
|
||||
#[cfg(feature = "native-api")]
|
||||
@@ -532,7 +569,7 @@ impl SubscriptionManager {
|
||||
diagnostics,
|
||||
)?;
|
||||
let nodes = parse_subscription_content_with_diagnostics(sub, &content, diagnostics)?;
|
||||
Ok((nodes, content))
|
||||
Ok((nodes, content, userinfo))
|
||||
}
|
||||
|
||||
async fn persist_content(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{Subscription, fetch_body, subscription_client};
|
||||
use super::{Subscription, SubscriptionUserinfo, fetch_body, subscription_client};
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::sync::{Mutex, mpsc, oneshot, watch};
|
||||
use tokio::task::{JoinHandle, JoinSet};
|
||||
@@ -10,7 +10,7 @@ type ThreadResult = Result<(), &'static str>;
|
||||
|
||||
struct Request {
|
||||
subscription: Subscription,
|
||||
reply: oneshot::Sender<anyhow::Result<Vec<u8>>>,
|
||||
reply: oneshot::Sender<anyhow::Result<(Vec<u8>, SubscriptionUserinfo)>>,
|
||||
}
|
||||
|
||||
struct NetworkThread {
|
||||
@@ -148,7 +148,10 @@ impl SubscriptionNetwork {
|
||||
Self::await_ready(&mut *self.state.lock().await).await
|
||||
}
|
||||
|
||||
pub(super) async fn fetch(&self, subscription: &Subscription) -> anyhow::Result<Vec<u8>> {
|
||||
pub(super) async fn fetch(
|
||||
&self,
|
||||
subscription: &Subscription,
|
||||
) -> anyhow::Result<(Vec<u8>, SubscriptionUserinfo)> {
|
||||
let sender = {
|
||||
let mut state = self.state.lock().await;
|
||||
Self::await_ready(&mut state).await?;
|
||||
|
||||
@@ -44,7 +44,7 @@ async fn completed_request_leaves_no_keepalive_before_pause() {
|
||||
.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\nbody")
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(fetch.await.unwrap().unwrap(), b"body");
|
||||
assert_eq!(fetch.await.unwrap().unwrap().0, b"body");
|
||||
// The marked client owns one connection per request and keeps no idle pool.
|
||||
peer_eof(&mut socket).await;
|
||||
network.pause().await.unwrap();
|
||||
@@ -104,7 +104,7 @@ async fn held_resolver() -> (
|
||||
Arc<SubscriptionNetwork>,
|
||||
Arc<BlockingResolver>,
|
||||
std::sync::mpsc::Sender<()>,
|
||||
JoinHandle<anyhow::Result<Vec<u8>>>,
|
||||
JoinHandle<anyhow::Result<(Vec<u8>, super::super::SubscriptionUserinfo)>>,
|
||||
) {
|
||||
let (entered, started) = oneshot::channel();
|
||||
let (release, released) = std::sync::mpsc::channel();
|
||||
|
||||
@@ -7,7 +7,7 @@ use tokio::sync::{mpsc, oneshot, watch};
|
||||
use tokio::task::{JoinHandle, JoinSet};
|
||||
use tracing::{info, warn};
|
||||
|
||||
use super::{SubscriptionManager, SubscriptionStore};
|
||||
use super::{SubscriptionManager, SubscriptionStore, SubscriptionUserinfo};
|
||||
use crate::control::ControlCommand;
|
||||
use crate::control::ReloadOutcome;
|
||||
use tokio::time::Instant;
|
||||
@@ -27,6 +27,7 @@ pub(crate) struct SubscriptionMergeReply {
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub(crate) struct ProviderLoad {
|
||||
pub(crate) updated_at: Option<SystemTime>,
|
||||
pub(crate) userinfo: SubscriptionUserinfo,
|
||||
pub(crate) cached: bool,
|
||||
pub(crate) error: Option<&'static str>,
|
||||
/// The configuration diagnostic code behind a `publication_rejected` error.
|
||||
@@ -179,7 +180,7 @@ pub(crate) fn validate_subscription_ids(subscriptions: &[Subscription]) -> anyho
|
||||
|
||||
struct FetchCompletion {
|
||||
authorized: AuthorizedSubscription,
|
||||
result: Option<anyhow::Result<Vec<Node>>>,
|
||||
result: Option<anyhow::Result<(Vec<Node>, SubscriptionUserinfo)>>,
|
||||
diagnostics: Vec<honk_config::diagnostic::DetailedDiagnostic>,
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ async fn fetch_once(
|
||||
}
|
||||
};
|
||||
let result = match fetched {
|
||||
Some(Ok((nodes, content))) => {
|
||||
Some(Ok((nodes, content, userinfo))) => {
|
||||
// Once a blocking cache write starts, its owner must join it even on pause/shutdown.
|
||||
SubscriptionManager::persist_content(
|
||||
&authorized.subscription,
|
||||
@@ -210,7 +211,7 @@ async fn fetch_once(
|
||||
0,
|
||||
)
|
||||
.await;
|
||||
Some(Ok(nodes))
|
||||
Some(Ok((nodes, userinfo)))
|
||||
}
|
||||
Some(Err(error)) => Some(Err(error)),
|
||||
None => None,
|
||||
@@ -224,6 +225,7 @@ async fn fetch_once(
|
||||
}
|
||||
struct Flight {
|
||||
authorized: AuthorizedSubscription,
|
||||
userinfo: SubscriptionUserinfo,
|
||||
#[cfg(feature = "native-api")]
|
||||
operation: Option<Box<dyn RefreshReport>>,
|
||||
}
|
||||
@@ -311,6 +313,7 @@ impl SupervisorState {
|
||||
id,
|
||||
Flight {
|
||||
authorized: provider.authorized.clone(),
|
||||
userinfo: SubscriptionUserinfo::default(),
|
||||
#[cfg(feature = "native-api")]
|
||||
operation: None,
|
||||
},
|
||||
@@ -434,6 +437,7 @@ impl SupervisorState {
|
||||
"Subscription runtime publication acknowledged"
|
||||
);
|
||||
observed.load.updated_at = Some(SystemTime::now());
|
||||
observed.load.userinfo = flight.userinfo;
|
||||
observed.load.cached = false;
|
||||
observed.load.error =
|
||||
matches!(reply.outcome, ReloadOutcome::CommittedDegraded { .. })
|
||||
@@ -455,6 +459,7 @@ impl SupervisorState {
|
||||
}
|
||||
(Ok(reply), None) if reply.outcome.accepted() => ProviderLoad {
|
||||
updated_at: Some(SystemTime::now()),
|
||||
userinfo: flight.userinfo,
|
||||
cached: false,
|
||||
error: matches!(reply.outcome, ReloadOutcome::CommittedDegraded { .. })
|
||||
.then_some("publication_degraded"),
|
||||
@@ -477,7 +482,8 @@ impl SupervisorState {
|
||||
fn fetched(&mut self, completion: FetchCompletion, command_tx: &mpsc::Sender<ControlCommand>) {
|
||||
let id = completion.authorized.subscription.id;
|
||||
match completion.result {
|
||||
Some(Ok(nodes)) => {
|
||||
Some(Ok((nodes, userinfo))) => {
|
||||
self.flights.get_mut(&id).unwrap().userinfo = userinfo;
|
||||
let command_tx = command_tx.clone();
|
||||
let task = self.publications.spawn(async move {
|
||||
let (result, wait) = oneshot::channel();
|
||||
@@ -537,6 +543,7 @@ impl SupervisorState {
|
||||
id,
|
||||
Flight {
|
||||
authorized: provider.authorized.clone(),
|
||||
userinfo: SubscriptionUserinfo::default(),
|
||||
operation: Some(operation),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -24,7 +24,13 @@ impl SupervisorState {
|
||||
Ok(Some(nodes)) => {
|
||||
honk_config::diagnostic::report_detailed_diagnostics(&diagnostics);
|
||||
let count = nodes.len();
|
||||
if !self.add_startup_nodes(&mut config.nodes, subscription, nodes, true) {
|
||||
if !self.add_startup_nodes(
|
||||
&mut config.nodes,
|
||||
subscription,
|
||||
nodes,
|
||||
true,
|
||||
SubscriptionUserinfo::default(),
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
crate::config_diagnostics::declare_provider_diagnostics(
|
||||
@@ -100,9 +106,9 @@ impl SupervisorState {
|
||||
} = completion;
|
||||
let subscription = authorized.subscription;
|
||||
match result {
|
||||
Some(Ok(nodes)) => {
|
||||
Some(Ok((nodes, userinfo))) => {
|
||||
let count = nodes.len();
|
||||
if self.add_startup_nodes(&mut config.nodes, &subscription, nodes, false) {
|
||||
if self.add_startup_nodes(&mut config.nodes, &subscription, nodes, false, userinfo) {
|
||||
startup_diagnostics
|
||||
.replace_provider(subscription.id, diagnostics);
|
||||
info!(
|
||||
@@ -159,6 +165,7 @@ impl SupervisorState {
|
||||
subscription: &Subscription,
|
||||
nodes: Vec<Node>,
|
||||
cached: bool,
|
||||
userinfo: SubscriptionUserinfo,
|
||||
) -> bool {
|
||||
let mut ids: HashSet<_> = current
|
||||
.iter()
|
||||
@@ -180,6 +187,7 @@ impl SupervisorState {
|
||||
current.extend(nodes);
|
||||
*load = ProviderLoad {
|
||||
updated_at: Some(SystemTime::now()),
|
||||
userinfo,
|
||||
cached,
|
||||
error: None,
|
||||
rejection: None,
|
||||
|
||||
@@ -278,6 +278,7 @@ async fn shutdown_joins_fetches_and_keeps_the_accepted_load() {
|
||||
.unwrap()
|
||||
.load = ProviderLoad {
|
||||
updated_at: Some(accepted_at),
|
||||
userinfo: SubscriptionUserinfo::default(),
|
||||
cached: true,
|
||||
error: Some("cache_load_failed"),
|
||||
rejection: None,
|
||||
@@ -356,7 +357,7 @@ fn shutdown_joins_queued_blocking_persistence() {
|
||||
}
|
||||
FetchCompletion {
|
||||
authorized: fetched,
|
||||
result: Some(Ok(Vec::new())),
|
||||
result: Some(Ok((Vec::new(), SubscriptionUserinfo::default()))),
|
||||
diagnostics,
|
||||
}
|
||||
});
|
||||
@@ -854,6 +855,7 @@ async fn startup_fetch_replaces_the_providers_own_nodes() {
|
||||
.unwrap()
|
||||
.load = ProviderLoad {
|
||||
updated_at: None,
|
||||
userinfo: SubscriptionUserinfo::default(),
|
||||
cached: true,
|
||||
error: Some("publication_rejected"),
|
||||
rejection: Some("duplicate-node-id"),
|
||||
|
||||
@@ -18,6 +18,46 @@ fn parse_clash_subscription(
|
||||
parse_clash_proxies(proxies, subscription_id)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn subscription_userinfo_parses_known_unsigned_fields() {
|
||||
let cases = [
|
||||
("", [None, None, None, None]),
|
||||
(
|
||||
"upload=422986054; download=5198408536; total=214748364800; expire=1796712849",
|
||||
[
|
||||
Some(422986054),
|
||||
Some(5198408536),
|
||||
Some(214748364800),
|
||||
Some(1796712849),
|
||||
],
|
||||
),
|
||||
(
|
||||
" upload = 0 ; download = 0 ; total = 0 ; expire = 0 ",
|
||||
[Some(0), Some(0), None, None],
|
||||
),
|
||||
(
|
||||
"download=12; ignored=34; upload=7",
|
||||
[Some(7), Some(12), None, None],
|
||||
),
|
||||
(
|
||||
"upload=-1; download=no; total=18446744073709551616; expire=1=2; broken",
|
||||
[None, None, None, None],
|
||||
),
|
||||
(
|
||||
"upload=18446744073709551615; total=1; expire=2",
|
||||
[Some(u64::MAX), None, Some(1), Some(2)],
|
||||
),
|
||||
];
|
||||
for (header, expected) in cases {
|
||||
let parsed = parse_subscription_userinfo(header);
|
||||
assert_eq!(
|
||||
[parsed.upload, parsed.download, parsed.total, parsed.expire],
|
||||
expected,
|
||||
"{header}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn private_literal_hosts_are_recognized_by_address_not_name() {
|
||||
for url in [
|
||||
|
||||
@@ -289,7 +289,7 @@ For accepted `.dae` rules, including those in credential-bearing sources, `/rule
|
||||
|
||||
### Provider observations and refresh
|
||||
|
||||
Admitted anonymous loopback requests read the same provider data as bearer-authenticated requests. Provider GETs do no networking. List accepts `limit` (1–1000, default 100) and `cursor`, with eight 30-second snapshots and 4 MiB aggregate retention; a list that cannot fit returns `503 snapshot_unavailable` with `Retry-After`. An unrecognised provider cursor returns `410 snapshot_expired`; a recognised cursor sent with different filters or a different `limit` returns `400 invalid_request`. IDs join accepted `Node.provider_id`. Subscriptions return their configured names and full URLs in `url_redacted`; the field name remains for compatibility. GET and successful operation results use the same representation. Usage and expiry remain null. A configured name matching the former `provider-<id>` label is an ordinary name, never an ID alias. Their status comes from the subscription owner: `ok` requires a successful usable publication; cached, pending, never-loaded, disabled or failed-with-retained-nodes providers are `stale`. `error` requires a real failure with no nodes. Never-loaded/disabled-without-cache rows have zero nodes and null update/error, not fabricated failures. Subscription rows also carry `download`, the route their fetches take from `download_detour`, shaped like the geodata route: `route` is `routing`, `direct` or `group`, and `group_id` is the group's `GET /groups` ID, null for other routes and for a group that no longer exists. File and inline rows report null. A failed fetch reports `last_error.code` `fetch_failed`, or `route_unavailable` when the subscription's download route has no usable node yet; see the [subscription reference](./subscription.md#fetch-persistence-and-recovery). A publication that configuration validation rejects, such as a node that duplicates a static node, reports `publication_rejected` with the diagnostic in `details.diagnostic_code` (for example `duplicate-node-id`); a failed refresh operation carries the same details.
|
||||
Admitted anonymous loopback requests read the same provider data as bearer-authenticated requests. Provider GETs do no networking. List accepts `limit` (1–1000, default 100) and `cursor`, with eight 30-second snapshots and 4 MiB aggregate retention; a list that cannot fit returns `503 snapshot_unavailable` with `Retry-After`. An unrecognised provider cursor returns `410 snapshot_expired`; a recognised cursor sent with different filters or a different `limit` returns `400 invalid_request`. IDs join accepted `Node.provider_id`. Subscriptions return their configured names and full URLs in `url_redacted`; the field name remains for compatibility. GET and successful operation results use the same representation. `traffic` and `expires_at` come from the provider's `subscription-userinfo` header and are null without it. A configured name matching the former `provider-<id>` label is an ordinary name, never an ID alias. Their status comes from the subscription owner: `ok` requires a successful usable publication; cached, pending, never-loaded, disabled or failed-with-retained-nodes providers are `stale`. `error` requires a real failure with no nodes. Never-loaded/disabled-without-cache rows have zero nodes and null update/error, not fabricated failures. Subscription rows also carry `download`, the route their fetches take from `download_detour`, shaped like the geodata route: `route` is `routing`, `direct` or `group`, and `group_id` is the group's `GET /groups` ID, null for other routes and for a group that no longer exists. File and inline rows report null. A failed fetch reports `last_error.code` `fetch_failed`, or `route_unavailable` when the subscription's download route has no usable node yet; see the [subscription reference](./subscription.md#fetch-persistence-and-recovery). A publication that configuration validation rejects, such as a node that duplicates a static node, reports `publication_rejected` with the diagnostic in `details.diagnostic_code` (for example `duplicate-node-id`); a failed refresh operation carries the same details.
|
||||
|
||||
`POST /providers/{id}/refresh` takes an empty body and optional `Idempotency-Key`, returning a 202 operation. Success requires actual revision-authorized runtime publication, not just fetch or cache write; disconnecting HTTP does not cancel admitted work. A distinct concurrent refresh for the same provider conflicts (409), while retained same-key replay returns the original operation first. Disabled providers, or a runtime without a subscription owner (`can_refresh: false`), return `404 capability_not_supported`; stopped/capacity-limited owners return 503. The virtual `inline` provider is not refreshable or deletable; it groups static non-builtin nodes, whose `provider_id` is `inline`. Builtins retain null provider ownership. Subscription IDs remain UUIDs.
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ PUT 仅在耐久写入并进入真实 reload 队列后返回 `202`;显式 POST
|
||||
|
||||
### Provider 观测与刷新
|
||||
|
||||
获准访问的匿名 loopback 请求与 bearer 认证请求读取相同的 provider 数据。Provider GET 不联网。订阅条目连接真实 SubscriptionSupervisor 观测与已接受节点的 `subscription_id`,`Node.provider_id` 可用于关联。订阅返回配置名称,`url_redacted` 返回完整 URL;为兼容客户端保留字段名。GET 与成功操作结果使用相同表示。未观测 usage/expiry 仍为 null。与旧 `provider-<id>` 标签相同的配置名称只是普通名称,不作为 ID 别名。从未加载、等待加载或禁用且无缓存时是 stale、零节点及 null 时间/错误;真实失败且无节点才是 error,保留旧/缓存节点时为 stale。订阅条目还带有 `download`,即由 `download_detour` 决定的拉取路由,结构与 geodata 路由相同:`route` 为 `routing`、`direct` 或 `group`,`group_id` 为该组在 `GET /groups` 中的 ID,其他路由或组已不存在时为 null。文件与 inline 条目为 null。拉取失败时 `last_error.code` 为 `fetch_failed`;订阅的下载路由尚无可用节点时为 `route_unavailable`,见[订阅参考](./subscription.md#拉取持久化与恢复)。配置校验拒绝发布时(例如节点与静态节点重复),`last_error.code` 为 `publication_rejected`,诊断代码写在 `details.diagnostic_code`(例如 `duplicate-node-id`);失败的 refresh operation 带相同的 details。列表 `limit` 默认 100、范围 1–1000,snapshot 上限 8 份/30 秒/4 MiB,放不下时返回 `503 snapshot_unavailable` 并带 `Retry-After`;游标无法识别时同样返回 `410 snapshot_expired`,带不同过滤器或 `limit` 的已识别游标返回 `400 invalid_request`。启用且有运行 supervisor 的订阅可 POST refresh;订阅已禁用或未挂接 supervisor(`can_refresh: false`)时返回 `404 capability_not_supported`;同 provider 的不同并发 refresh 为 409,保留的幂等重放先于冲突检查。刷新成功须真实 revision-fenced publication 被接受,fetch 或写缓存不等于成功,HTTP 断连不丢失结果。虚拟 inline provider 不可刷新/删除;它关联 `provider_id: inline` 的静态非 builtin 节点,builtin 归属保持 null,订阅 ID 仍为 UUID。
|
||||
获准访问的匿名 loopback 请求与 bearer 认证请求读取相同的 provider 数据。Provider GET 不联网。订阅条目连接真实 SubscriptionSupervisor 观测与已接受节点的 `subscription_id`,`Node.provider_id` 可用于关联。订阅返回配置名称,`url_redacted` 返回完整 URL;为兼容客户端保留字段名。GET 与成功操作结果使用相同表示。`traffic` 与 `expires_at` 来自 provider 的 `subscription-userinfo` 响应头,没有该响应头时为 null。与旧 `provider-<id>` 标签相同的配置名称只是普通名称,不作为 ID 别名。从未加载、等待加载或禁用且无缓存时是 stale、零节点及 null 时间/错误;真实失败且无节点才是 error,保留旧/缓存节点时为 stale。订阅条目还带有 `download`,即由 `download_detour` 决定的拉取路由,结构与 geodata 路由相同:`route` 为 `routing`、`direct` 或 `group`,`group_id` 为该组在 `GET /groups` 中的 ID,其他路由或组已不存在时为 null。文件与 inline 条目为 null。拉取失败时 `last_error.code` 为 `fetch_failed`;订阅的下载路由尚无可用节点时为 `route_unavailable`,见[订阅参考](./subscription.md#拉取持久化与恢复)。配置校验拒绝发布时(例如节点与静态节点重复),`last_error.code` 为 `publication_rejected`,诊断代码写在 `details.diagnostic_code`(例如 `duplicate-node-id`);失败的 refresh operation 带相同的 details。列表 `limit` 默认 100、范围 1–1000,snapshot 上限 8 份/30 秒/4 MiB,放不下时返回 `503 snapshot_unavailable` 并带 `Retry-After`;游标无法识别时同样返回 `410 snapshot_expired`,带不同过滤器或 `limit` 的已识别游标返回 `400 invalid_request`。启用且有运行 supervisor 的订阅可 POST refresh;订阅已禁用或未挂接 supervisor(`can_refresh: false`)时返回 `404 capability_not_supported`;同 provider 的不同并发 refresh 为 409,保留的幂等重放先于冲突检查。刷新成功须真实 revision-fenced publication 被接受,fetch 或写缓存不等于成功,HTTP 断连不丢失结果。虚拟 inline provider 不可刷新/删除;它关联 `provider_id: inline` 的静态非 builtin 节点,builtin 归属保持 null,订阅 ID 仍为 UUID。
|
||||
|
||||
### 原生日志与运行时设置
|
||||
|
||||
|
||||
Reference in new issue
Block a user