diff options
| author | tv <tv@krebsco.de> | 2026-10-30 17:33:59 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-30 17:33:59 +0100 |
| commit | 236a11a4798574b9c710dde4b97231ff4cade86d (patch) | |
| tree | 1203102bc44aa9bcc002646934d59c5a3f3bcd83 /src/api | |
| parent | f091fb2a9188f686e5b1f9012c510a1b3c8ad840 (diff) | |
build stats and peers as values
Both /admin/stats and /peers can now be built as plain values
(stats::collect, peers::peer_list), so the upcoming dashboard
can reuse them.
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/peers.rs | 10 | ||||
| -rw-r--r-- | src/api/stats.rs | 3 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/api/peers.rs b/src/api/peers.rs index eeb3fb2..da714d0 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -114,6 +114,12 @@ pub(crate) struct DeletePeerQuery { pub(crate) async fn list_peers( State(state): State<AppState>, ) -> Result<Json<PeerListResponse>, StatusCode> { + Ok(Json(peer_list(&state).await)) +} + +/// What `GET /peers` answers, for others to show too (the dashboard). +pub(crate) async fn peer_list(state: &AppState) -> PeerListResponse { + let state = state.clone(); let snapshot = state.peers_snapshot().await; let now = Instant::now(); @@ -173,13 +179,13 @@ pub(crate) async fn list_peers( } let local_heads = state.doc.read().await.heads().len(); - Ok(Json(PeerListResponse { + PeerListResponse { local_alias: state.alias.clone(), local_addresses: state.transport.local_addresses(), local_epoch: local_epoch.into(), local_heads, peers, - })) + } } /// `DELETE /peers/{pk}`: forgets a peer swarm-wide. diff --git a/src/api/stats.rs b/src/api/stats.rs index 889b675..114f644 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -249,7 +249,8 @@ pub(crate) async fn get_stats(State(state): State<AppState>, headers: HeaderMap) } } -async fn collect(state: &AppState) -> StatsResponse { +/// What `GET /admin/stats` answers as JSON, for others to show too (the dashboard). +pub(crate) async fn collect(state: &AppState) -> StatsResponse { let node = state.stats.snapshot(); let (heads, tier, remakes) = { |
